eye-therapy-2 / Assets / Scripts / Interactables / Button / ButtonBehaviour.cs
ButtonBehaviour.cs
Raw
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit;

public class ButtonBehaviour : MonoBehaviour
{
    [SerializeField] float pressLength = 0.02f;
    [SerializeField] EVENT_TYPE pressEvent = EVENT_TYPE.DUMMY;
    public bool pressed = false;

    public float PressLength { get; private set; } = 0.02f;

    private void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Button")
        {
            pressed = true;
            EventManager.Instance.PostNotification<Object>(pressEvent, this);
        }
    }

    private void OnTriggerExit(Collider other)
    {
        pressed = false;
    }

#if UNITY_EDITOR
    private void OnValidate()
    {
        PressLength = pressLength;
    }
#endif
}