So i was experimenting with a drag and shoot platformer, but I have a problem where the animator won’t go to the ‘‘flying’’ state.
The idle and prepare states (when I’m dragging the player) object work fine but the animator won’t transition to the flying state or sometimes just works for a split second.

Is there any way how to solve this?
Here is the code for reference:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DragNShoot : MonoBehaviour
{
public float power= 10f;
public Rigidbody2D rb;
public Animator anim;
public Vector2 minPower;
public Vector2 maxPower;
TrajectoryLine tl;
Camera cam;
Vector2 force;
Vector3 startPoint;
Vector3 endPoint;
private void Start()
{
cam = Camera.main;
tl = GetComponent<TrajectoryLine>();
}
private void Update()
{
if (Input.GetMouseButtonDown(0))
{
startPoint = cam.ScreenToWorldPoint(Input.mousePosition);
startPoint.z = 15;
}
if (Input.GetMouseButton(0))
{
Vector3 currentPoint = cam.ScreenToWorldPoint(Input.mousePosition);
currentPoint.z = 15;
tl.RenderLine(startPoint, currentPoint);
anim.SetBool("preparing", true);
}
else
{
anim.SetBool("preparing", false);
}
if (Input.GetMouseButtonUp(0))
{
endPoint = cam.ScreenToWorldPoint(Input.mousePosition);
endPoint.z = 15;
anim.SetBool("flying", true);
force = new Vector2(Mathf.Clamp(startPoint.x - endPoint.x, minPower.x, maxPower.x), Mathf.Clamp(startPoint.y - endPoint.y, minPower.y, maxPower.y));
rb.AddForce(force * power, ForceMode2D.Impulse);
tl.EndLine();
}
else
{
anim.SetBool("flying", false);
}
}
}