Hi, I’m having some trouble with using a coroutine for our game. I have a script which looks a bit like this:
var myBool: boolean = true;
function myCoroutine(time: float)
{
myBool = false;
yield WaitForSeconds(time);
myBool= true;
}
function OnCollisionEnter(col: Collision)
{
if(col.gameObject.tag == "collisionObject")
{
print("collided with: " + col.gameObject.name);
StartCoroutine(myCoroutine(2));
}
}
I’m using this to make sure the player loses control of its gameobject when it collides with some specific objects. This should wait for a short while, then return the control to the player.
What it is actually doing tho, is either not setting the bool to false to begin with, or perhaps it is just ignoring the yield statement and setting the bool right back to true. Either way the player keeps control all the time, which seems strange.
Does anybody know why this isn’t working?
I’m probably doing something stupid here, and I’m probably just asking this because my brain died on me, but thanks anyway!