onTriggerEnter problem

Aaargh. I’m having problems with what (seems to me) to be a simple thing.

I’ve got an animated object (animated in Maya), that moves through the scene. I’d like to have it so that as this moving object runs into triggers, it triggers events (animation, audio cues, etc…).

I’ve made a cube to act as the trigger (Is Trigger is checked within its Box Collider). The script below is attached to it:

 var soldierDavis: GameObject; 
    
    function onTriggerEnter (other : Collider) { 
	
    if (other.gameObject.tag == "HotCar") // 
       { 
			print("I've been triggered");
          soldierDavis.animation.CrossFade ("walk"); 
       } 
    }

The object that is animated is tagged as “HotCar” and also has a Box Collider. But as HotCar moves through the trigger, it never triggers. What in the world am I doing wrong?

Thanks!

as far as i can tell from your code, this could have 2 reasons:

  1. OnTriggerEnter never gets triggered at all
  2. the ‘if’-statement never returns true

the most common issue with OnTriggerEnter is that people forget to attach a rigidbody to 1 of the objects, in the documentation it says:

if the function does get called and the ‘if’-statement is the problem … well check the tag on the object :wink:

Thanks. Turns out, the problem was no rigid body, and my stupid mistake of using onTriggerEnter instead of OnTriggerEnter…bleh.