Hello all, I’m very new to Unity but I have some ideas on how to use it. For an assignment, I have to learn how to use triggers and restart the game when one enters it. Right now I have a sprite with the tag “Player” and accompanied by a Character Controller. The "Player is going to be chased by a gas cloud (tagged as “Gas”) and when he enters its trigger, the game restarts. The “Gas” is a sprite that moves on its own. The game is running on a 2D plane, like a platformer. Right now, I have an empty game object that is child to “Gas” and made it into a sphere collider. Also, “Gas” does not have a rigid body. I didn’t think it would need one seeing that “Player” already has the Character Controller attached. My script is as follows:
#pragma strict
function Start ()
{}
function OnTriggerEnter (player : Collider)
{
if(player.gameObject.tag == "Player")
Application.LoadLevel(Application.loadedLevel);
}
function OnTriggerExit (player : Collider)
{
if(player.gameObject.tag == "Player")
Application.LoadLevel(Application.loadedLevel);
}
This code doesn’t seem to work, so what can I do to have the game restart when my “Player” sprite enters the trigger? Please help!