1234567891011121314151617181920212223242526272829303132333435 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Valve.VR.InteractionSystem;
- public class CheckVisible : MonoBehaviour
- {
- Interactable ParentInteractable;
- bool CurrentState;
- Canvas GuiCanvas;
- void Start()
- {
- ParentInteractable = GetComponentInParent<Interactable>();
- GuiCanvas = GetComponentInChildren<Canvas>();
- CurrentState = true;
- }
- // Update is called once per frame
- void Update()
- {
- bool newState;
- if (ParentInteractable.attachedToHand)
- newState = true;
- else
- newState = false;
- if (CurrentState != newState)
- UpdateVisibility(newState);
- }
- private void UpdateVisibility(bool newState)
- {
- GuiCanvas.enabled = newState;
- CurrentState = newState;
- }
- }
|