Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Cant change animator bools

Discussion in 'Animation' started by Misko2356, Dec 6, 2023.

  1. Misko2356

    Misko2356

    Joined:
    Feb 13, 2022
    Posts:
    6
    Hello, i want to create a simple script that does swap between idle and walk animations, i dont have any errors, but this code basicly dont enable or disable the bools. Please, could you help me somehow?

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class AnimationController : MonoBehaviour
    4. {
    5.     private Animator animator;
    6.  
    7.     void Start()
    8.     {
    9.         animator = GetComponent<Animator>();
    10.     }
    11.  
    12.     void Update()
    13.     {
    14.         if (Input.GetKey(KeyCode.W))
    15.         {
    16.             Debug.Log("holding W");
    17.             animator.SetBool("isWalking", true);
    18.             animator.SetBool("isIdle", false);
    19.         }
    20.         else
    21.         {
    22.             Debug.Log("idle");
    23.             animator.SetBool("isIdle", true);
    24.             animator.SetBool("isWalking", false);
    25.         }
    26.     }
    27. }
    28.