74 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			74 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
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 actionA = null;
 | 
						|
    public UnityEvent OnPressA = new UnityEvent();
 | 
						|
 | 
						|
    public InputAction actionB = null;
 | 
						|
    public UnityEvent OnPressB = new UnityEvent();
 | 
						|
 | 
						|
    public InputAction actionX = null;
 | 
						|
    public UnityEvent OnPressX = new UnityEvent();
 | 
						|
 | 
						|
    public InputAction actionY = null;
 | 
						|
    public UnityEvent OnPressY = new UnityEvent();
 | 
						|
 | 
						|
    private void Awake()
 | 
						|
    {
 | 
						|
        actionA.started += ButtonAPressed;
 | 
						|
        actionB.started += ButtonBPressed;
 | 
						|
        actionX.started += ButtonXPressed;
 | 
						|
        actionY.started += ButtonYPressed;
 | 
						|
    }
 | 
						|
 | 
						|
    private void OnDestroy()
 | 
						|
    {
 | 
						|
        actionA.started -= ButtonAPressed;
 | 
						|
        actionB.started -= ButtonBPressed;
 | 
						|
        actionX.started -= ButtonXPressed;
 | 
						|
        actionY.started -= ButtonYPressed;
 | 
						|
    }
 | 
						|
 | 
						|
    private void OnEnable()
 | 
						|
    {
 | 
						|
        actionA.Enable();
 | 
						|
        actionB.Enable();
 | 
						|
        actionX.Enable();
 | 
						|
        actionY.Enable();
 | 
						|
    }
 | 
						|
 | 
						|
    private void OnDisable()
 | 
						|
    {
 | 
						|
        actionA.Disable();
 | 
						|
        actionB.Disable();
 | 
						|
        actionX.Disable();
 | 
						|
        actionY.Disable();
 | 
						|
    }
 | 
						|
 | 
						|
    private void ButtonAPressed(InputAction.CallbackContext context)
 | 
						|
    {
 | 
						|
        OnPressA.Invoke();
 | 
						|
    }
 | 
						|
 | 
						|
    private void ButtonBPressed(InputAction.CallbackContext context)
 | 
						|
    {
 | 
						|
        OnPressB.Invoke();
 | 
						|
    }
 | 
						|
 | 
						|
    private void ButtonXPressed(InputAction.CallbackContext context)
 | 
						|
    {
 | 
						|
        OnPressX.Invoke();
 | 
						|
    }
 | 
						|
 | 
						|
    private void ButtonYPressed(InputAction.CallbackContext context)
 | 
						|
    {
 | 
						|
        OnPressY.Invoke();
 | 
						|
    }
 | 
						|
}
 |