This repository has been archived on 2023-09-13. You can view files and clone it, but cannot push or open issues or pull requests.
station_obscurum_unity/Assets/Scripts/Game/Optimizer.cs

41 lines
923 B
C#
Raw Normal View History

using UnityEngine;
2023-06-01 20:25:46 +02:00
namespace Game {
/// <summary>
2023-06-01 17:03:48 +02:00
/// Attach this behavior to a master room collider. Enables everything in this room OnTriggerEnter of [tag]
/// disables everything in this room OnTriggerExit of [tag]
/// </summary>
public class Optimizer : MonoBehaviour
{
2023-06-01 17:03:48 +02:00
[SerializeField] public string Tag;
[SerializeField] private GameObject[] references;
[SerializeField] private bool beginDisabled = true;
private void Start()
{
2023-06-01 17:03:48 +02:00
if (beginDisabled) Disable();
}
2023-06-01 17:03:48 +02:00
private void OnTriggerEnter(Collider other)
{
2023-06-01 17:03:48 +02:00
if (other.CompareTag(Tag)) Enable();
}
2023-06-01 17:03:48 +02:00
private void OnTriggerExit(Collider other)
{
2023-06-01 17:03:48 +02:00
if (other.CompareTag(Tag)) Disable();
}
2023-06-01 17:03:48 +02:00
public void Enable()
{
2023-06-01 17:03:48 +02:00
foreach (var go in references) go.SetActive(true);
}
2023-06-01 17:03:48 +02:00
public void Disable()
{
2023-06-01 17:03:48 +02:00
foreach (var go in references) go.SetActive(false);
}
2023-06-01 20:25:46 +02:00
}
2023-06-01 17:03:48 +02:00
}