55 lines
1.1 KiB
C#
55 lines
1.1 KiB
C#
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
/// <summary>
|
||
|
/// 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
|
||
|
{
|
||
|
[SerializeField]
|
||
|
public string Tag;
|
||
|
[SerializeField]
|
||
|
private GameObject[] references;
|
||
|
[SerializeField]
|
||
|
private bool beginDisabled = true;
|
||
|
private void Start()
|
||
|
{
|
||
|
if (beginDisabled)
|
||
|
{
|
||
|
Disable();
|
||
|
}
|
||
|
}
|
||
|
public void Enable()
|
||
|
{
|
||
|
foreach (GameObject go in references)
|
||
|
{
|
||
|
go.SetActive(true);
|
||
|
}
|
||
|
}
|
||
|
public void Disable()
|
||
|
{
|
||
|
foreach (GameObject go in references)
|
||
|
{
|
||
|
go.SetActive(false);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void OnTriggerEnter(Collider other)
|
||
|
{
|
||
|
if (other.CompareTag(Tag))
|
||
|
{
|
||
|
Enable();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void OnTriggerExit(Collider other)
|
||
|
{
|
||
|
if (other.CompareTag(Tag))
|
||
|
{
|
||
|
Disable();
|
||
|
}
|
||
|
}
|
||
|
}
|