77 lines
2.1 KiB
C#
77 lines
2.1 KiB
C#
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<TextMeshProUGUI>().text = "<font=\"Urbscape SDF\"><mark=#00000>" + "no go! " + "</mark>";
|
|
FindActiveGoalTimer();
|
|
//goalTimer goalTimer = levels.GetComponentInChildren<goalTimer>(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<goalTimer>();
|
|
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!");
|
|
}
|
|
}
|