using UnityEngine; using UnityEngine.XR; using Fusion; using TMPro; using Fusion.Addons.ConnectionManagerAddon; namespace BNG { public class Chair : NetworkBehaviour { public Transform player; public Transform sitMan; private UnityEngine.XR.InputDevice leftController; [Networked] public bool networkedFill { get; set; } public RTLTMPro.RTLTextMeshPro text; public bool near; void Start() { if (!text) text = GetComponentInChildren(); leftController = InputDevices.GetDeviceAtXRNode(XRNode.LeftHand); GameObject playerObj = GameObject.FindGameObjectWithTag("Player"); if (playerObj) player = playerObj.transform; } void Update() { if (!Object || !Object.IsValid) return; if (!player) return; near = Vector3.Distance(transform.position, player.transform.position) < 1.5f; // Change text color based on proximity Color nearColor = near ? Color.yellow : Color.white; nearColor.a = 0.6f; text.color = nearColor; if (!ConnectionManager.instance.runner.IsRunning || (player.GetComponent().sit && !networkedFill)) return; text.gameObject.SetActive(!networkedFill); if (near) { bool isPressed = false; if (leftController.TryGetFeatureValue(CommonUsages.primaryButton, out bool buttonPressed)) { isPressed = buttonPressed; } if (isPressed || Input.GetKeyDown(KeyCode.T)) { SetSit(); } } } public void SetSit() { if (!Object || !Object.IsValid) return; if (!ConnectionManager.instance.runner.IsRunning || (player.GetComponent().sit && !networkedFill)) return; Debug.Log("Sit/Stand button was pressed!"); if (!player.GetComponent().sit) { sitMan = player; // Align player position with chair player.GetComponent().sit = true; player.GetComponent().chair = this; player.GetComponent().isKinematic = true; player.position = new Vector3(transform.position.x, transform.position.y, transform.position.z); SetFill(true); // Chair is now filled } else if (networkedFill && sitMan == player && !ConnectionManager.instance.presentation) { Invoke("StandUp", 0.3f); } } public void StandUp() { if (!Object || !Object.IsValid) return; sitMan = null; SetFill(false); // Chair is now empty player.GetComponent().sit = false; player.GetComponent().MaxVerticalVelocity = 10; player.GetComponent().isKinematic = false; } void SetFill(bool value) { if (!Object || !Object.IsValid) return; networkedFill = value; Debug.Log("SetFill called with value: " + value); } } }