- Home /
I can't get any collision check to work...
ok so i have a cube that i want the player to hit to end the level...i have named the cube "EndCube". Here is the script...
function OnCollisionEnter(collision : Collision)
{
if (collision.gameObject == "EndCube") {
Application.LoadLevel("3");
}
}
No matter what i do...i can't get the collision to work. I attached this script to my player.
Answer by aldonaletto · Apr 09, 2013 at 12:37 AM
Collisions are reported only when a rigidbody hits a collider - if your player is a CharacterController, no collisions will happen.
Usually it's better to make the EndCube object a trigger, and use OnTriggerEnter in the player script:
function OnTriggerEnter(other: Collider){
if (other.name == "EndCube"){
Application.LoadLevel("3");
}
}
NOTE: Anyway, you could not compare collision.gameObject to "EndCube": the first is a game object reference, and the latter is a string
Your answer
Follow this Question
Related Questions
getting udp package info inside unity (GlovePIE) 0 Answers
how do you actually stop a game? 3 Answers
Ending the game 2 Answers