- Home /
Stuck while solving a Coroutine problem
Hey guys, I’ve been stuck on this problem for almost two days, and I can’t seem to be able to figure it out on my own, so I would really appreciate your help. First of all, here’s my code.
function Update ()
{
if ((takeTurns.machineTurn == true)&&(takeTurns.playerTurn == false))
JustACoroutine();
}
function JustACoroutine()
{
yield WaitForSeconds(5);
for (var f = 0; f <50; f++)
{
for (var w = 0; w < 50; w++)
{
if (createBricks.globalArray[w,f,0] != null)
{
if(createBricks.globalArray[w,f,0].gameObject.GetComponent(Rigidbody) != null)
{
Destroy(createBricks.globalArray[w,f,0].gameObject);
}
}
}
}
allMurdered = true;
}
The problem is, allMurdered remains true indefinitely. That is, long after takeTurns.playerTurn had been switched to true and takeTurns.machineTurn to false. Here’s the bit of code that does that:
function LookForClicks()
{
if (createBricks.turnClicks == 4)
{
playerTurn = false;
machineTurn = true;
createBricks.turnClicks = 0;
yield WaitForSeconds(6);
murderer.allMurdered = false;
playerTurn = true;
machineTurn = false;
}
}
I believe that the problem lies in having two coroutines running simultaneously, but then I don’t understand them very well and can’t quite put my hand on the flawed part.
Again, any help at all very appreciated.
Your answer
Follow this Question
Related Questions
Toggling bools automatically using coroutines 1 Answer
Yield WaitForTrue? 1 Answer
Trouble Resuming after Yielding while Inside Coroutine 1 Answer
Coroutines not passing yield 1 Answer
Coroutine a function within a loop? 1 Answer