rabidus-test/Assets/BNG Framework/Scripts/Extras/ToggleActiveOnInputAction.cs

32 lines
840 B
C#
Raw Permalink Normal View History

2023-07-24 16:38:13 +03:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
namespace BNG {
/// <summary>
/// This script will toggle a GameObject whenever the provided InputAction is executed
/// </summary>
public class ToggleActiveOnInputAction : MonoBehaviour {
public InputActionReference InputAction = default;
public GameObject ToggleObject = default;
private void OnEnable() {
InputAction.action.performed += ToggleActive;
}
private void OnDisable() {
InputAction.action.performed -= ToggleActive;
}
public void ToggleActive(InputAction.CallbackContext context) {
if(ToggleObject) {
ToggleObject.SetActive(!ToggleObject.activeSelf);
}
}
}
}