- Home /
Function call is not working
So I have a function, that is called when all agents are dead. I have also a timer. When the timer is up, all agents are set to their original position and they are set to acitve. I have a timer script and a GameManager script. When the time is up I call from the timer script TimeIsUpGM() and everything works fine, the agents are set back and active. And within the GameManager script I am doing all the process. It is controlling the respawning and the death of the agents. But when all agents are dead before the time is up, the agents won't set back to their pos and won't set active. It always waits for the timer. Here How I call it from the timer:
-timer script:
--In Update:
instanceGM.TimeIsUpGM();
-GameManager Script:
--In TimeIsUpGM:
EnemyDone()
timer.ResetTimer()
--In EnemyDone:
SetEnemysActive()
for (int i = 0; i < listOfAgent.Count; i++)
listOfAgent[i].GetComponent<EnemyController>().Done();
In SetEnemysActive:
foreach (GameObject obj in listOfAgent)
{
obj.SetActive(true);
}
So this works from the timer script. And when I do the call, when all agents are dead it does not work:
-GameManager:
--AgentDead:
if(AgentsAreDead())
TimeIsUpGM();
I put in the methods some Debug.Log to check if it is going in the method but yes it is. The problem is that it is not doing the same when I call it from the timer script.
EDIT
Now to solve the problem, I am doing this in the timer script and it works:
if (instanceGM.GetAreAgentsDead())
instanceGM.TimeIsUpGM();
But I don't like the solution. I would rather do this in the GameManager, but I guess there is a problem with the instance?