Unity animation not completing

Input.GetKeyDown

is only true in the one frame the button went down.

Returns true during the frame the user starts pressing down the key identified by the key KeyCode enum parameter.


You rather want to use Input.GetKey which stay true as long as the key stays pressed.

Returns true while the user holds down the key identified by the key KeyCode enum parameter


alternatively in order to not have redundant accesses you could also simply use

horizontalInput = Input.GetAxis("Horizontal");

animator.SetBool("isMoving", !Mathf.Approximately(horizontalInput, 0));

And as a general note: Cache the component references and don’t use GetComponent over and over again!

[SerializeField] private Rigidbody _rigidbody;

private void Awake ()
{
    if(!_rigodbody) _rigidbody = GetComponent<Rigidbody>();
}

then later everywhere use _rigidbdoy instead of GetComponent<Rigidbody>()

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top