- Home /
Problem is not reproducible or outdated
OP has stated his problem is fixed and has abandoned this thread at Mar 24
How to restart scene with trigger?
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!
put debug in ontrigger and ensure you are getting the triggerevent you expect to
Application.LoadLevel(Application.loadedLevel);
in the braces, you have to put the number / name of the level, that you want to load.
@instruct9r ... Doing it the way they did IS putting a number in as the level they want to load. Application.LoadLevel(Application.loadedLevel); will re-load the current level.
@SenorFlowers: Don't post an answer just with the text "fixed it". Either post a real answer which actually answers / solves the problem or if you think the question won't help others, close it. If you can't close it just ask for close with a comment.
Answer by abdala · Mar 25, 2014 at 01:37 AM
#pragma strict
function Start ()
{}
function OnTriggerEnter (player : Collider)
{
Application.LoadLevel(LEVEL NAME);
}
Follow this Question
Related Questions
Trigger Spawning? 1 Answer
Colliding two GameObjects 1 Answer
OnTriggerEnter is not running! Need help with collision. 2 Answers
Missing taps on triggers/collider 0 Answers