- Home /
collision script to next scene
im trying to make a script that when you collide with a game obj you are transferred to a new scene... how do i write this?
Answer by ferro · Apr 17, 2012 at 09:58 PM
You can detect collision by having
OnCollisionEnter(Collision c)
method in your MonoBehaviour. When you detect collision you can change scene with
Application.loadLevel("level name")
method
i get an error message BCE0005: $$anonymous$$ identifier: 'OnCollisionEnter'
function Update () { OnCollisionEnter(Collision); Application.loadLevel("title"); }
is this the wrong scripting?
You have absolutely no idea, have you? Read the manual, learn some basic scripting, get comfortable with Unity's scripting environment. Then ask questions on this site. The scripting reference is right there on your computer, so you have no excuse for not reading it. If you read the script reference end-to-end (even skim-reading it is alright!) then you'll have more of an idea of how to put this stuff together than about 90% of the registered users on this site.
Answer by kevinseligmann · Apr 18, 2012 at 02:30 AM
As suggested by @Lo0NuhtiK you need to check when your object collides. To do that, you do exactly what he said. You can also filter collision objects by tag or name:
function OnCollisionEnter(other : Collision){
if(other.gameObject.name == "SomeObject"){
Application.loadlevel("Level name");
}
if(other.gameObject.tag == "SomeTag"){
Application.loadlevel("Level name");
}
}
Your answer
Follow this Question
Related Questions
move camera when it collides with a trigger 1 Answer
activate gui on trigger enter 1 Answer
RigidBody - GameObject moves but mesh stays! 1 Answer
Inverse 2D Collider, is this possible? 0 Answers