If I press “w” my character will do a walk animation, but if I let go of it, it will go bag to its idle position. However when I tried running if I let go of the shift key the W key or both it will still continue to do the running animation. Why is this? Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Anim : MonoBehaviour
{
Animator animator;
// Start is called before the first frame update
void Start()
{
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
bool isWalking = animator.GetBool("Walking");
bool isRunning = animator.GetBool("Running");
bool walking = Input.GetKey("w");
bool runPressed = Input.GetKey("left shift");
if (!isWalking && walking)
{
animator.SetBool("Walking", true);
}
if (isWalking &!walking)
{
animator.SetBool("Walking", false);
}
if (!isRunning && (walking && runPressed))
{
animator.SetBool("Running", true);
}
if (!isRunning && (!walking || !runPressed))
{
animator.SetBool("Running", false);
}
}
}