I have a 3rd person game and i made some animations to open a door and in my door code it gets the animator of both the door and player to play 2 animations: 1 the door opening and 2 the player opening the door.
But after both are done the players animation doesn’t return to idle.
it goes back to the first frame of the door open animation of the player.
using UnityEngine;
public class DoorController : MonoBehaviour
{
public Animator animator;
public Animator playerAnimator;
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
Debug.Log("Player entered trigger");
}
}
private void OnTriggerExit(Collider other)
{
if (other.CompareTag("Player"))
{
Debug.Log("Player left trigger");
}
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.E) && animator != null && animator.isActiveAndEnabled)
{
animator.SetTrigger("OpenDoor");
if (playerAnimator != null && playerAnimator.isActiveAndEnabled)
{
playerAnimator.SetTrigger("OpenDoor");
}
}
}
}