//OnTriggerEnter2D is sent when another object enters a trigger collider attached to this object (2D physics only). private void OnTriggerEnter2D(Collider2D other) { //Check if the tag of the trigger collided with is Exit. if (other.tag == "Exit") { //Invoke the Restart function to start the next level with a delay of restartLevelDelay (default 1 second). Invoke("Restart", restartLevelDelay); //Disable the player object since level is over. enabled = false; } //Check if the tag of the trigger collided with is Food. else if (other.tag == "Food") { //Add pointsPerFood to the players current food total. food += pointsPerFood; //Update foodText to represent current total and notify player that they gained points foodText.text = "+" + pointsPerFood + " Food: " + food; //Call the RandomizeSfx function of SoundManager and pass in two eating sounds to choose between to play the eating sound effect. SoundManager.instance.RandomizeSfx(eatSound1, eatSound2); //Disable the food object the player collided with. other.gameObject.SetActive(false); } //Check if the tag of the trigger collided with is Soda. else if (other.tag == "Soda") { //Add pointsPerSoda to players food points total food += pointsPerSoda; //Update foodText to represent current total and notify player that they gained points foodText.text = "+" + pointsPerSoda + " Food: " + food; //Call the RandomizeSfx function of SoundManager and pass in two drinking sounds to choose between to play the drinking sound effect. SoundManager.instance.RandomizeSfx(drinkSound1, drinkSound2); //Disable the soda object the player collided with. other.gameObject.SetActive(false); } else if (other.tag == "Trap") { Trap trap = other.GetComponent <Trap>(); trap.ActivateTrap(this); } }