using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro; public class NoGoTracker : MonoBehaviour { public GameObject levels; public GameObject debug; private goalTimer goaltimer; // Start is called before the first frame update void Start() { levels = GameObject.Find("levels"); } // Update is called once per frame void Update() { } public void OnTriggerEnter(Collider collision) { if (collision.tag == "gamecollider") { //debug.GetComponent().text = "" + "no go! " + ""; FindActiveGoalTimer(); //goalTimer goalTimer = levels.GetComponentInChildren(true); // Include inactive objects if needed if (goaltimer != null) { goaltimer.OnHitObject(); } else { } } } private void FindActiveGoalTimer() { // Loop through all children of "levels" foreach (Transform level in levels.transform) { if (level.gameObject.activeSelf) // Find the active level { Transform goalmanager = level.Find("goalmanager"); // Find goalManager child if (goalmanager != null) { goaltimer = goalmanager.GetComponent(); if (goaltimer != null) { Debug.Log("Found GoalTimer on active level: " + level.name); return; // Stop searching once found } else { Debug.LogError("goalmanager exists but has no GoalTimer component!"); } } else { Debug.LogError("Active level found but no goalmanager child!"); } } } Debug.LogError("No active level with GoalTimer found!"); } }