Files
Deroc_Virtual_3D/Assets/FPS/Scripts/UI/ToggleGameObjectButton.cs
T
Alex38Lyon 878ea46cac update
2025-06-03 12:00:47 +02:00

28 lines
702 B
C#

using Unity.FPS.Game;
using UnityEngine;
using UnityEngine.EventSystems;
namespace Unity.FPS.UI
{
public class ToggleGameObjectButton : MonoBehaviour
{
public GameObject ObjectToToggle;
public bool ResetSelectionAfterClick;
void Update()
{
if (ObjectToToggle.activeSelf && Input.GetButtonDown(GameConstants.k_ButtonNameCancel))
{
SetGameObjectActive(false);
}
}
public void SetGameObjectActive(bool active)
{
ObjectToToggle.SetActive(active);
if (ResetSelectionAfterClick)
EventSystem.current.SetSelectedGameObject(null);
}
}
}