- Home /
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(). With a question like this. Please Google the site first. You would have found this easily with something like "Unity3d load new level".
Answer by Daphoeno · Apr 14, 2013 at 12:27 PM
function OnTriggerEnter (other : Collider) {
if(other.gameObject.tag == "Player"){
Application.LoadLevel(LevelNumberGoesHere);
}
}
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.
Your answer
Follow this Question
Related Questions
destroy object after Application.LoadLevel 1 Answer
Level requested not loading, prev. one is instead? 2 Answers
Load next level when reach score 1 Answer
Can't click gameobject when over another trigger? 1 Answer
enable a canvas on trigger 2 Answers