UP-Viagg-io/Viagg-io/Assets/Scripts/OnButtonPress.cs

40 lines
726 B
C#
Raw Normal View History

2024-04-10 09:44:23 +02:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
public class OnButtonPress : MonoBehaviour
{
[Tooltip("Actions to check")]
public InputAction action = null;
// When the button is pressed
public UnityEvent OnPress = new UnityEvent();
private void Awake()
{
action.started += Pressed;
}
private void OnDestroy()
{
action.started -= Pressed;
}
private void OnEnable()
{
action.Enable();
}
private void OnDisable()
{
action.Disable();
}
private void Pressed(InputAction.CallbackContext context)
{
OnPress.Invoke();
}
}