- Home /
Collision detection problem
Hello everybody, well I need to detect when the player touches a simple collider (I need this to change the level) but until now I just can detect when other objects collide, not the player.
This is the code I use:
function OnCollisionEnter (collisionInfo : Collision) {
if (collisionInfo.gameObject.tag == "Cube"){
Application.LoadLevel ("GameOver");
}
}
I have already used the tag "Player" but it is not working,I have changed the tag, what tag shoud I use or what can I do to solve the problem??
Answer by Steffen Franz · Jan 20, 2011 at 10:43 PM
Unity Script Reference: "In contrast to OnTriggerEnter, OnCollisionEnter is passed the Collision class and not a Collider".
Use OnTriggerEnter instead and compare the tags (don't forget to check "IsTrigger" on the BoxCollider or whatever Collider you are using.
function OnTriggerEnter (other : Collider) {
if (other.CompareTag ("Player")) {
Application.LoadLevel("level");
}
}
Your answer
Follow this Question
Related Questions
Play annimation on collision not working. 1 Answer
Player detecting collision when crouching 1 Answer
What's wrong with OnCollisionEnter? 2 Answers
How to block collision between selected objects 0 Answers
how do i correctly use a box collider 0 Answers