- Home /
onCollisionEnter
I have a cylinder using a mesh collider and rigid body. I also have 2 blocks(cubes) as goals. The cylinder's tag is "SodaCan" The block's tags are "Goal1" and "Goal2"
I created a script called "GoalDetection" and attached it to "Goal1" and "Goal2" GoalDetection uses this exact code:
function onCollisionEnter(other : Collision) {
if (other.gameObject.tag == "SodaCan") {
Debug.Log("Goal Scored");
}
}
My problem is that even when the soda can is right on top of either goal "Goal Scored" is not printed.
Does anybody know any solutions or what i did wrong?
I am using unity iphone
Answer by Tetrad · Jun 06, 2010 at 03:05 AM
http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnCollisionEnter.html
You probably need to capitalize the 'O', like this:
function OnCollisionEnter(other : Collision)
{
if (other.gameObject.tag == "SodaCan")
{
Debug.Log("Goal Scored");
}
}
Do you have triggers set up on your goal objects? I.e. colliders with the "is trigger" checkmark added?
Re-read the documentation I linked to you, specifically this point: "OnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider."
So if your goals don't have either rigidbodies or colliders, OnCollisionEnter won't get called.
Your answer
Follow this Question
Related Questions
Collision detections fails to re-detect an object 1 Answer
WALL collision detection problem... help!!!! 0 Answers
collision detection 4 Answers
Detect collision from a another object,Detect collision from another script 2 Answers
Collision Detection 2 Answers