This commit is contained in:
manhduyhoang90
2026-05-26 09:46:57 +07:00
commit 167a617e09
1758 changed files with 1757605 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
using Unity.FPS.Game;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
namespace Unity.FPS.UI
{
public class ToggleGameObjectButton : MonoBehaviour
{
public GameObject ObjectToToggle;
public bool ResetSelectionAfterClick;
private InputAction m_CancelAction;
void Start()
{
m_CancelAction = InputSystem.actions.FindAction("UI/Cancel");
m_CancelAction.Enable();
}
void Update()
{
if (ObjectToToggle.activeSelf && m_CancelAction.WasPressedThisFrame())
{
SetGameObjectActive(false);
}
}
public void SetGameObjectActive(bool active)
{
ObjectToToggle.SetActive(active);
if (ResetSelectionAfterClick)
EventSystem.current.SetSelectedGameObject(null);
}
}
}