trigger animation problems

Hi having problems with some supposedly simple code to trigger an animation of doors sliding open.

the doors are called doorleft and doorright, the trigger box is called trigger and the script is attached to all objects but this error comes up.
here’s my script:

var Animator : GameObject; //Assign this in the editor character with animation
     
    function OnTriggerEnter(){
        Animator.Animation.Play("doorleft");
        
}

2 Answers

2

Does your gameobject has an Animation Component attached?, does that animation exists in the list of attached animation?, what’s the exact error. Make sure your game object have an animation component and this animation called “doorleft” actually exists. BTW you could use

Transform animatedObject;

animatedObject.animation.Play(“doorleft”);

check the lowercasing for “Animation”

BTW, I recommend not to call your object Animator, could also give you some issues, since may be reserved word on unity.

none of the objects are called animator animation component is attached, I tried the script annd nothing.

Don’t assign the script to all the object.
Instead have it only on the trigger. Also remove the capital A from your variable’s name.
Then, in your code add animator=GameObject.Find(" the name of your door’s model with the animation ");

Put the Find code in Start() though, not Update so that it will only try to find it once.