Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Bool Animation Freezes in Transition [Video explanation & Code]

Discussion in 'Animation' started by AEXII, Nov 21, 2022.

  1. AEXII

    AEXII

    Joined:
    Nov 15, 2022
    Posts:
    4
    Animation transitions not working with Bool variables.

    Animations from what I can see are all set up correctly to transition.

    I have spent a week focusing on player movement, learning scripts, watching tutorials from many different YouTubers and issues with the animations have continuously stopping me progressing.

    Link to Video Explanation:


    I realized OBS did not show the code. Here's the code:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class AnimationStateController : MonoBehaviour
    6. {
    7.     Animator animator;
    8.    
    9.     // Start is called before the first frame update
    10.     void Start()
    11.     {
    12.         animator = GetComponent<Animator>();
    13.     }
    14.  
    15.     // Update is called once per frame
    16.     void Update()
    17.     {
    18.         bool isWalking = animator.GetBool("isWalking");
    19.         bool forwardPressed = Input.GetKey("w");
    20.         // if player pressed w key
    21.         if (forwardPressed)
    22.         {
    23.             // then set the isWalking boolean to be true
    24.             animator.SetBool("isWalking", true);
    25.         }
    26.         // if player is not pressing w key
    27.             if (!Input.GetKey("w"))
    28.         {
    29.             // then set the isWalking boolean to be false
    30.             animator.SetBool("isWalking", false);
    31.         }
    32.  
    33.     }
    34. }
    35.