Animator reuses to transition to a state

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);
        }
    }

}

With debugging!

First fix the animator. Get it working 100% without the script / code: just manipulate the properties and make it work 100% using only the editor.

Once that works, move onto the code and debug it.

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

You are setting “flying” to false immediately after you set it to true.

        if (Input.GetMouseButtonUp(0))
        {
...
            anim.SetBool("flying", true);
...
        }
        else
        {
            anim.SetBool("flying", false);
        }

GetMouseButtonUp is only true for the one frame where the mouse button transitions from down to up. GetMouseButtonUp will return false on all other frames.