Trying to delay an animatoin

Hello,

I’m trying to use C# to code a time delay for a door animation to go. The code I have seems fine but nothing changes. The animation works just fine but it isnt delayed. Here is the code. I also attached a screenshot of the animator if that helps at all.

public class DoorDelay : MonoBehaviour {
public int startDelay;
private Animator anim;

// Use this for initialization
void Start () {
StartCoroutine(delay());
}

// Update is called once per frame
void Update () {

}
IEnumerator delay() {
anim = GetComponent();
yield return new WaitForSeconds(startDelay);
anim.Play(“DoorRig|DoorOpen”);
}
}

Maybe the animation is auto playing when you start the scene?
I think it might do that if you just have one state (that is the default state).
Comment out StartCoroutine(delay()) and play the scene to see if that is the case.

If it is you could perhaps make a closed state is set to the default state and a transition from that to the door open state.

I am more of an animator than a coder… so a grain of salt.

Maybe you can try to call the coroutine from update instead of start. Just add a boolean to make sure that after the coroutine finishes, it is no longer played again.

Also, you may want to put “anim = GetComponent();” from start instead of the coroutine.