UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"When certain objects are destroyed, activate an object"
using UnityEngine; public class ObjectActivation : MonoBehaviour { public GameObject objectToActivate; public string[] objectTagsToCheck; private int objectsToDestroyCount; void Start() { objectsToDestroyCount = objectTagsToCheck.Length; objectToActivate.SetActive(false); } void Update() { if (objectsToDestroyCount <= 0) { objectToActivate.SetActive(true); } } public void OnDestroyedObject(GameObject destroyedObject) { foreach (string tag in objectTagsToCheck) { if (destroyedObject.CompareTag(tag)) { objectsToDestroyCount--; break; } } } } public class ObjectDestruction : MonoBehaviour { private ObjectActivation objectActivation; void Start() { objectActivation = FindObjectOfType<ObjectActivation>(); } void OnDestroy() { objectActivation.OnDestroyedObject(gameObject); } }