Loading a New Level

Hi,

Ok, I’m really new to coding so forgive me if I’m missing something obvious. I am making a game where ghosts chase the player through a maze and when a ghost catches a player, the player is sent back to start (the level is reloaded). I’m looking for a really simple way to make this work. I was thinking putting a collider on the ghosts, set it as a trigger, and once that collider was triggered the level would restart. I’m just confused on how to script the reloading of a level onto a collider (I’ve done with lights before but I just don’t know how to get a level to load/reload in the first place)
Thanks!

You are likely looking for [Application.LoadLevel()][1]. With a question like this. Please Google the site first. You would have found this easily with something like "Unity3d load new level". [1]: http://docs.unity3d.com/Documentation/ScriptReference/Application.LoadLevel.html

1 Answer

1

function OnTriggerEnter (other : Collider) {
if(other.gameObject.tag == “Player”){
Application.LoadLevel(LevelNumberGoesHere);
}
}

thanks! I was able to figure it out.

Personal taste, I prefer to use string as parameter. The reason is simple, if you have 20 scenes and you decide to add a scene in second position, either you end up with scene two being scene 21 or you have to move everything by one everywhere it occurs. Using strings, you won't have to change anything.