UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"when 25 cubes with the tag Training get destroyed, object appears"
using UnityEngine; public class ObjectAppearOnCubesDestroyed : MonoBehaviour { public GameObject objectToAppear; public int requiredCubesDestroyed = 25; private int cubesDestroyed = 0; void Start() { objectToAppear.SetActive(false); } void Update() { if (cubesDestroyed >= requiredCubesDestroyed) { objectToAppear.SetActive(true); } } public void CubeDestroyed(GameObject cube) { if (cube.CompareTag("Training")) { cubesDestroyed++; } } } // Attach this script to each cube with the "Training" tag public class TrainingCube : MonoBehaviour { private ObjectAppearOnCubesDestroyed objectAppearScript; void Start() { objectAppearScript = FindObjectOfType<ObjectAppearOnCubesDestroyed>(); } void OnDestroy() { objectAppearScript.CubeDestroyed(gameObject); } }