0
\$\begingroup\$

I have set my animation to play through a script I made but it's not playing. I have all the references correct my spelling is correct as well. My code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AnimationTrigger : MonoBehaviour
{
    [SerializeField] private Animator myDoor;
    [SerializeField] private string DoorOpen = "DoorOpen";

    private void OnTriggerEnter(Collider other)
    {
        if(other.CompareTag("Player"))
        {
            myDoor.Play(DoorOpen, 0, 0.0f);
            Debug.Log("Animation Played");
        }
    }
    
}


Picture of my animator window:

enter image description here

\$\endgroup\$
0

1 Answer 1

0
\$\begingroup\$

See Animator.Play.

When you specify a state name, or the string used to generate a hash, it should include the name of the parent layer. For example, if you have a Bounce state in the Base Layer, the name is Base Layer.Bounce.

So try this:

[SerializeField] private string DoorOpen = "Base Layer.DoorOpen";

*Playing the animation directly is not recommended, you can try to control the parameters to let the animation state machine control the animation playing.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .