CheckVisible.cs 847 B

1234567891011121314151617181920212223242526272829303132333435
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Valve.VR.InteractionSystem;
  5. public class CheckVisible : MonoBehaviour
  6. {
  7. Interactable ParentInteractable;
  8. bool CurrentState;
  9. Canvas GuiCanvas;
  10. void Start()
  11. {
  12. ParentInteractable = GetComponentInParent<Interactable>();
  13. GuiCanvas = GetComponentInChildren<Canvas>();
  14. CurrentState = true;
  15. }
  16. // Update is called once per frame
  17. void Update()
  18. {
  19. bool newState;
  20. if (ParentInteractable.attachedToHand)
  21. newState = true;
  22. else
  23. newState = false;
  24. if (CurrentState != newState)
  25. UpdateVisibility(newState);
  26. }
  27. private void UpdateVisibility(bool newState)
  28. {
  29. GuiCanvas.enabled = newState;
  30. CurrentState = newState;
  31. }
  32. }