- Home /
next level
i am making a game with multiple levels using java script what code do i use if i want to make it so when the character touches a block it takes him/her to the next scene
Answer by BiG · Jan 15, 2012 at 04:18 PM
The logic is the following:
function OnCollisionEnter (theCollision : collider){
if(theCollision.gameObject.tag == "block"){
next_level=(Application.loadedLevel)+1;
Application.LoadLevel(next_level);
}
}
Obviously, some assumptions must be done:
The code above must be attached to the player;
Your levels must be indexed in increasing order (File -> Build Settings);
Your blocks have the tag "block" attached;
And, finally, you have to handle the special case about the final level.
Your answer
![](https://koobas.hobune.stream/wayback/20220613063014im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Switch to the next round only works in the editor. 0 Answers
Next LEVEL Load Problem. 2 Answers
How do I make the screen fade when it goes into the next level? 0 Answers
Load Level on Collision 1 Answer
How to script a death fall and respawn? 0 Answers