Files
HauntedBloodlines/Assets/Scripts/Debugging/CanvasOnOff.cs
2025-05-29 22:31:40 +03:00

54 lines
1.6 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CanvasOnOff : MonoBehaviour
{
[SerializeField] private List<Canvas> CanvasUIElements;
[SerializeField] private bool CanvasUIIsEnabled;
private void Start()
{
// Find all GameObjects with the specified tag
GameObject[] taggedObjects = GameObject.FindGameObjectsWithTag("PlayerGameplayHUD");
// Loop through each GameObject found and add its Canvas component to the list
foreach (GameObject obj in taggedObjects)
{
Canvas canvas = obj.GetComponent<Canvas>();
if (canvas != null)
{
CanvasUIElements.Add(canvas);
}
else
{
Debug.LogWarning("GameObject with tag 'PlayerGameplayHUD' does not have a Canvas component.");
}
}
}
// Update is called once per frame
void Update()
{
if (!CanvasUIIsEnabled && Input.GetKeyDown(KeyCode.Alpha1))
{
foreach (var canvasUIElements in CanvasUIElements)
{
canvasUIElements.enabled = true;
PlayerOverlapSphereDetectorManager.GetInstance().enabled = true;
}
CanvasUIIsEnabled = true;
}
else if (CanvasUIIsEnabled && Input.GetKeyDown(KeyCode.Alpha1))
{
foreach (var canvasUIElements in CanvasUIElements)
{
canvasUIElements.enabled = false;
PlayerOverlapSphereDetectorManager.GetInstance().enabled = false;
}
CanvasUIIsEnabled = false;
}
}
}