Прерывание анимации

Не могу выполнить прыжок, если не попаду в тайминг конца любой анимации(анимация ожидания, бега и т.д).Как мне прервать текущую анимацию?(с помощью animator) На просторах интернета не смог найти подходящего ответа на этот вопрос.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Movement : MonoBehaviour
{
   public float NormalSpeed = 5;
   public float RunSpeed = 10;
   public float JumpHeight = 10;
   private float normalspeed;
   private float runspeed;
   private Animator anim;
   private bool isRun = false;
   private bool isGround;
   private bool isSliding = false;
   Rigidbody2D rb2d;
   private void Start()
   {
       rb2d = GetComponent<Rigidbody2D>();
       anim = GetComponent<Animator>();
   }
   void Update()
   {
       if (Input.GetKeyDown(KeyCode.LeftShift))
       {
           isRun = true;
       } else if (Input.GetKeyUp(KeyCode.LeftShift)) { isRun = false; }
       normalspeed = NormalSpeed * Time.fixedDeltaTime;
       runspeed = RunSpeed * Time.fixedDeltaTime;
   }

   private void OnTriggerEnter2D(Collider2D collision)
   {
       if(collision.tag == "Ground") { isGround = true; Debug.Log("IsGround=true"); }
   }

   private void OnTriggerExit2D(Collider2D collision)
   {
       if (collision.tag == "Ground") { isGround = false;Debug.Log("isground=false"); }
   }

   private void FixedUpdate()
   {
       if (Input.GetAxis("Horizontal") > 0)
       {
           if (isRun && isGround)
           {
               anim.Play("RunRight");
               transform.position += new Vector3(runspeed, 0, 0) * Input.GetAxis("Horizontal");
           }
           else if (isGround)
           {
               anim.Play("WalkRight");
               transform.position += new Vector3(normalspeed, 0, 0) * Input.GetAxis("Horizontal");
               if (Input.GetKeyDown(KeyCode.S))
               {
                   isSliding = true;
                   anim.Play("SlideRight");
                   rb2d.AddForce(new Vector2(normalspeed, 0), ForceMode2D.Impulse);
                   
               }
           }
           else
           {
               transform.position += new Vector3(normalspeed, 0, 0) * Input.GetAxis("Horizontal");
           }
       }

       if (Input.GetAxis("Horizontal") < 0) {
           if (isRun && isGround)
           {
               transform.position += new Vector3(runspeed, 0, 0) * Input.GetAxis("Horizontal");
               anim.Play("RunLeft");
           }
           else if (isGround)
           {
               anim.Play("WalkLeft");
               transform.position += new Vector3(normalspeed, 0, 0) * Input.GetAxis("Horizontal");
               if (Input.GetKeyDown(KeyCode.S))
               {
                   isSliding = true;
                   anim.Play("SlideLeft");
                   rb2d.AddForce(new Vector2(normalspeed, 0), ForceMode2D.Impulse);

               }
           }
           else
           {
               transform.position += new Vector3(normalspeed, 0, 0) * Input.GetAxis("Horizontal");
           }

       }

       //if (Input.GetKeyDown(KeyCode.S))
       //{
       //    if (Input.GetAxis("Horizontal") > 0 && isGround)
       //    {
       //        isSliding = true;
       //        anim.Play("SlideRight");
       //        rb2d.AddForce(new Vector2(normalspeed, 0), ForceMode2D.Impulse);
       //    }
       //    else if (Input.GetAxis("Horizontal") < 0 && isGround)
       //    {
       //        isSliding = true;
       //        anim.Play("SlideLeft");
       //        rb2d.AddForce(new Vector2(normalspeed, 0), ForceMode2D.Impulse);
       //    }
       //}
       else if (Input.GetKeyUp(KeyCode.S))
       {
           isSliding = false;
       }

       if (Input.GetKeyDown(KeyCode.Space) && isGround)
       {
           anim.Play("Jump");
           rb2d.AddForce(new Vector2(0, JumpHeight), ForceMode2D.Impulse);
       }


       if (Input.GetAxis("Horizontal") == 0 && isGround)
       {
           anim.Play("Afk");   
       }

   }
}

Ответы (0 шт):