/** * Function that cleans up destroying the food stuff and checks if the game is over. */ void OnEndPointCollision() { GameObject[] foodstuff = GameObject.FindGameObjectsWithTag("MouthFood"); // find all foodstuff on the game // check if there are any foodstuff left if (foodstuff.Length == 1 && foodSpawner.end) // if this is the last foodstuff, then we won { // handle win condition GameObject chooseBackground = GameObject.Find("MouthChooseBackground"); // find the background chooser for // the level selection texture if (chooseBackground != null) // if we found the background chooser get the level { level = chooseBackground.GetComponent <MouthLoadLevelCounter>(); level.nextLevel(); // increase the level counter to correctly load the next // level (if there is one) } //Application.LoadLevel("MouthStats"); // load the stats screen for the completed level Instantiate(endGameScript); } else // otherwise if there are more food stuff just destroy the current one that hit the end point { Destroy(this.gameObject); } }