- Home /
How Do I Exit Level?
ok so im going to put like a flag at the end of every level called Exit_Flag. What i want is for when my character touches the flag it goes to the next level. Anyone could make me a script for this to work and show me what to do with it? I would really appreciate this. Thanks if you can help.
Answer by Statement · Jan 12, 2011 at 05:05 PM
Make a trigger near your flag. When your player touches it, change level. This can be done with a simple script. You add this script to the trigger. You can then also write what level you want to load when the trigger is entered.
var nextLevel : int;
function OnTriggerEnter(collider : Collider) { if (collider.CompareTag("Player")) { Application.LoadLevel(nextLevel); } }
Alternatively you can add the script to the player and check if it hit the flag, that way you don't need to edit every level.
function OnControllerColliderHit(hit : ControllerColliderHit)
{
if (hit.collider.name == "Exit_Flag")
{
Application.LoadLevel(Application.loadedLevel + 1);
}
}
I have fixed the error in the code. I should have tried it on my machine before submitting it.
Your answer
Follow this Question
Related Questions
Problem to go to another world scene in level select lock/unlock 0 Answers
Level changing and build issue 2 Answers
Load the Same Level, but Different Configurations? 2 Answers
Two player collision ? 1 Answer
scene loader issue 0 Answers