Urgent help needed with animation trigger!!

Hey there,

I am having an awful lot of problems trying to create a trigger that activates an animated hatch door. The idea is that the player having found a ball places it in a hole and a hatch on a boathouse opens dropping down some items for the player to use in the next challenge. I have created an empty game object and ticked the trigger box as well as applied this code to it named doortrigger3.js.

var door : GameObject; 

function OnTriggerEnter (collision : Collider)
{
if (collision.gameObject.name == "Ball")

door.animation.Play ("door_01");
}

The animation I created using Unity’s own animation system is definitely names door_01 and the sphere collider object is named Ball yet when I place the sphere into the trigger nothing happens at all. If I check “play animation automatically” before I press play the animation does play fine. I just want it to play when the player does this one simple challenge. I am pretty new to Unity so am probably messing something up somewhere.

I have NO idea where I am going wrong and it is the final piece to my Final MA project which is due in next wednesday.

Any help will be greatly appreciated.

Hey,

Does ‘Ball’ have a Collider attached to it? If so, try setting some Debug.Logs like this:

var door : GameObject; 

function OnTriggerEnter (collision : Collider)
{
    Debug.Log("Something hit! Checking to see if it's the ball...")
    if (collision.gameObject.name == "Ball")
    {
        Debug.Log("Ball hit!");
        door.animation.Play ("door_01");
    }
}

That might help you locate the problem better. Good luck!

Thanks much, I resolved the problem in the end through the help of a friend. It was a problem with heirachy and the way I set up the animation. Solved now but cheers for the debug script, it helped identify the issue!