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
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.