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

Need help with dashing cooldown animation

Discussion in '2D' started by Loik-San, Jul 29, 2021.

  1. Loik-San

    Loik-San

    Joined:
    Jun 15, 2021
    Posts:
    12
    so basically i got this dashing script but with the touch control method i created it wont make the cool down animation.

    here is the dashing script:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class DashScript : MonoBehaviour
    6. {
    7.  
    8.   public float dashCooldown;
    9.   public bool canIDash = true;
    10.   public bool dashing = false;
    11.   public Vector2 savedVelocity;
    12.   public Animator animator;
    13.  
    14.   void Update ()
    15.   {
    16.       if(dashCooldown > 0)
    17.       {
    18.           animator.SetBool("coolingdown?", true);
    19.           canIDash = false;
    20.           dashCooldown -= Time.deltaTime;
    21.           animator.SetBool("coolingdown?", true);
    22.       }
    23.       if(dashCooldown <= 0)
    24.       {
    25.           animator.SetBool("coolingdown?", false);
    26.           canIDash = true;
    27.           animator.SetBool("coolingdown?", false);
    28.       }
    29.  
    30.       }
    31.  
    32.  
    33.   public void dashButton() {
    34.  
    35.     if(canIDash == true){
    36.           savedVelocity = GetComponent<Rigidbody2D>().velocity;
    37.           GetComponent<Rigidbody2D>().velocity =  new Vector2(GetComponent<Rigidbody2D>().velocity.x*25f, GetComponent<Rigidbody2D>().velocity.y);
    38.           dashCooldown = 1;
    39.     }
    40.  
    41.  
    42.   }
    43. }
     
  2. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,452
    So add some Debug.Logs your If blocks and the dashButton function. Make sure they are calling at the appropriate times or even calling at all.

    As a clean code tip, you can just change that if(dashCooldown <= 0) to an Else since you only have 2 if blocks and it is either > 0 or not.

    As for the actual animation, make sure you have everything in animator set up properly. So when you are testing, dont just look at the Debug.Log messages but look at the animator and make sure it is transitioning when its supposed to as well.