Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

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

Discussion in 'Animation' started by AEXII, Nov 21, 2022 at 2:03 PM.

  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.  
     
unityunity