SlotMachineInteraction.cs
using Sandbox;
namespace Casino.RpSlot;
public sealed class SlotMachineInteraction : Component
{
[Property] public float MaxUseDistance { get; set; } = 100f;
[Property] public string UseAction { get; set; } = "Use";
protected override void OnUpdate()
{
// Côté joueur local uniquement
if ( Connection.Local == null ) return;
var camera = Scene.Camera;
if ( camera == null ) return;
var eye = camera.WorldPosition;
var forward = camera.WorldRotation.Forward;
var tr = Scene.Trace
.Ray( eye, eye + forward * MaxUseDistance )
.Run();
bool looking = tr.Hit && tr.GameObject == GameObject;
if ( looking && Input.Pressed( UseAction ) )
{
var ui = tr.GameObject.Components.GetInChildren<SlotMachineUI>( true );
if ( ui != null ) ui.IsEngaged = !ui.IsEngaged;
}
}
}