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

more ▼

asked Jun 06, 2010 at 03:02 AM

Aspyn palatnick gravatar image

Aspyn palatnick
1 9 6 9

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first


You probably need to capitalize the 'O', like this:

function OnCollisionEnter(other : Collision) 
    if (other.gameObject.tag == "SodaCan") 
        Debug.Log("Goal Scored"); 
more ▼

answered Jun 06, 2010 at 03:05 AM

Tetrad gravatar image

8.2k 63 70 148

it didn't work.

Jun 06, 2010 at 05:17 PM Aspyn palatnick

Do you have triggers set up on your goal objects? I.e. colliders with the "is trigger" checkmark added?

Jun 06, 2010 at 07:34 PM Tetrad

No should I put a trigger?

Jun 07, 2010 at 08:40 PM Aspyn palatnick

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.

Jun 07, 2010 at 10:26 PM Tetrad
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Jun 06, 2010 at 03:02 AM

Seen: 13642 times

Last Updated: Jun 06, 2010 at 04:22 AM