您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
26 行
670 B
26 行
670 B
using UnityEngine;
|
|
|
|
public class ObjectActivator : MonoBehaviour
|
|
{
|
|
[SerializeField] string activatorTag = null;
|
|
[SerializeField] bool deactivateOnExit = false;
|
|
[SerializeField] GameObject[] objects = null;
|
|
|
|
private void OnTriggerEnter2D(Collider2D collision)
|
|
{
|
|
if (collision.CompareTag(activatorTag))
|
|
{
|
|
foreach (var obj in objects)
|
|
obj.SetActive(true);
|
|
}
|
|
}
|
|
|
|
private void OnTriggerExit2D(Collider2D collision)
|
|
{
|
|
if (deactivateOnExit && collision.CompareTag(activatorTag))
|
|
{
|
|
foreach (var obj in objects)
|
|
obj.SetActive(false);
|
|
}
|
|
}
|
|
}
|