Hey. I’m trying to fire a lose game function once which takes a second to pass through from my Update function. It fires when a game object is below or at a certain y position. For some reason, the script does not go into the function at all. Here’s the bit of code I’m working with:
if(gameObject.tag == "UpCube" &&
gameObject.transform.position.y <= 4.0f &&
loseToggle == 0)
{
loseToggle = 1;
LoseGame();
}
IEnumerator LoseGame ()
{
Debug.Log("losegame!!");
container.SetActive(false);
yield return new WaitForSeconds (0.25f);
container.SetActive(true);
yield return new WaitForSeconds (0.25f);
container.SetActive(false);
yield return new WaitForSeconds (0.25f);
container.SetActive(true);
yield return new WaitForSeconds (0.25f);
Application.LoadLevel(0);
}
The set active and false back to back thing is to make the items inside the container blink before the game goes to back to start after losing.