OnTriggerEnter not working

Hey there. I’m pretty new to Unity but I am learning how to code now. The problem is the “OnTriggerEnter” function is not working. It doesn’t even change color. I got the code from a youtube tutorial so I know it works. Heres the part of the code.

function OnTriggerEnter(other : Collider){

Do you have a Rigidbody component on one of the two objects? I believe at least one of them needs to have one.

“Note that trigger events are only sent if one of the colliders also has a rigid body attached.”

Check this link out: Unity3D Documentation - Physics

Scroll down to the section “Collision action matrix”. This chart will tell you what types of colliders can set off the different trigger types.

I just ran into this problem as well. In Hierarchy view, I have a parent object with one child object with the same name. Looks like I inadvertently assigned the script handling the OnTriggerEnter event to the parent object, but the collider to the child object. Adding collider to the parent object fixed it. I’m still very new, but I am surprised that having an OnTriggerEnter event in a script attached to object without collider does not generate a compile error or warning message.

(Unity Version 4.1.2f1)

Maybe it helps

2nd reply

OK, sorry I’m jumping on the band wagon a bit here…but I have just run into this problem myself!

heres the code im using:

var Sound : AudioClip;
function OnTriggerEnter(){ audio.PlayOneShot(Sound);
}

I have been following this tutorial on activating sound with a trigger: - YouTube

I followed exactly as he does, but when it comes to entering the code, (at 3:01) my OnTriggerEnter wont change blue. (and consequently doesn’t work)

Any ideas?

Oh and I’ve tried adding a Rigidbody on as mentioned above and that doesn’t work either.