- Home /
Move to next level on collide
Hey guys! I need help. I made a simple level and I want my character to collide with the "end point" (a simple cube) and go to the next level. Lots of scripts hate me and I want a script that makes me move to next level. I tried this one:
OnCollisionEnter()
{
application.LoadLevel();
}
and that didnt work.
Can you give me a script that makes me move to the next level please. (Also: should my character have anything special attached to him like a rigidbody???)
Thanks
You have to put a scene name or scene number in the () of load level. It should look like this OnCollisionEnter() { Application.LoadLevel(1); }
If I put in the scene name don't I have to put it in quotes
Converted your answer to a comment under the question. Since its not clear what answer you where commenting on. Dont forget to mark correct answers(s) so the question is marked as answered.
Hi Linus,
I thought I'd posted my comment under the script that worked for me which wasn't the one you've moved it to. The one that worked for me was: var levelToLoad : String;
function OnTriggerEnter(hit : Collider) { Application.LoadLevel(levelToLoad); }
Answer by Ashkan_gc · Apr 30, 2010 at 06:12 PM
first you should add the scene to the list of scenes in file/build settings... menu. check the is trigger property of your character's collider. add a collider and a rigidbody to the box (end point). in rigidbody properties check the is kinematic property. then you can write
function OnTriggerEnter ()
{
Application.LoadLevel ("scenename");
}
have fun coding. scripts don't hate you :)
I have to create a script file? Where do I put the code?
The box collider I attached to a soda can instantly transports me to the next level without me touching it while I have "Is Trigger" checked on this script I put on the soda. HELP!
As Soon As I start $$anonymous$$y Game It Loads New Level PLZZZZZ HELP
Answer by Eric5h5 · Apr 30, 2010 at 06:02 PM
You have to specify the level to load in Application.LoadLevel. Also you have to write "Application" correctly (not "application"). You need a rigidbody if you want to have collisions.
Answer by karl_ · May 15, 2010 at 02:48 AM
Here's a completed script allowing you to set the next scene in the inspector. Make sure the plane/object you walk in to has "Is Trigger" marked. No rigidbody necessary.
//Script to revert winning player back to main menu
var levelToLoad : String;
function OnTriggerEnter(hit : Collider) { Application.LoadLevel(levelToLoad); }//END FUNCTION ONTRIGGERENTER
@karl_ could you make the object transparent then still have the script saying when it hits that object it spawns it out of the game?
What if there is no next scene what if that is the end of the game? (For now I want to start with one level)
Answer by CyberUnits · Jul 08, 2016 at 03:53 PM
@ntawesome pickle If the new level starts loading when starting your scene, than that probably means that the player already is touching an trigger collider. You could specify the object you want by adding an if statement.