How to Disable a Function from the same script?

Hi, I have a script which add force to a Ball when we drag Mouse OR Touch on screen just like angry bird. But when I drag mouse on screen force is added to ball which is fine. But when we drag again even if ball is in air it force is added again. I want to add force just one time. How can i disable force if it is already added? Check my script codes.

using UnityEngine;

public class GameManager : MonoBehaviour
{
    #region Singleton class: GameManager

    public static GameManager Instance;

    void Awake ()
    {
        if (Instance == null) {
            Instance = this;
        }
    }

    #endregion

    Camera cam;

    public Ball ball;
    public Trajectory trajectory;
    [SerializeField] float pushForce = 4f;

    bool isDragging = false;

    Vector2 startPoint;
    Vector2 endPoint;
    Vector2 direction;
    Vector2 force;
    float distance;

    //---------------------------------------
    void Start ()
    {
        cam = Camera.main;
        ball.DesactivateRb ();
    }

    void Update ()
    {
        if (Input.GetMouseButtonDown (0)) {
            isDragging = true;
            OnDragStart ();
        }
        if (Input.GetMouseButtonUp (0)) {
            isDragging = false;
            OnDragEnd ();
        }

        if (isDragging) {
            OnDrag ();
        }
    }

    //-Drag--------------------------------------
    void OnDragStart ()
    {
        ball.DesactivateRb ();
        startPoint = cam.ScreenToWorldPoint (Input.mousePosition);

        trajectory.Show ();
    }

    void OnDrag ()
    {
        endPoint = cam.ScreenToWorldPoint (Input.mousePosition);
        distance = Vector2.Distance (startPoint, endPoint);
        direction = (startPoint - endPoint).normalized;
        force = direction * distance * pushForce;

        //just for debug
        Debug.DrawLine (startPoint, endPoint);


        trajectory.UpdateDots (ball.pos, force);
    }

    void OnDragEnd ()
    {
        //push the ball
        ball.ActivateRb ();

        ball.Push (force);

        trajectory.Hide ();

       
    }

}

by adding state logic.
you can use a switching mechanism that keeps track of the last state and to prohibit dragging until a certain condition is met.

bool _draggingState = false;
bool _draggingShouldWork = true; // let's say true is a default state, to enable this initially

void OnDragStart() {
  if(!_draggingShouldWork) return;
  _draggingShouldWork = false;
  _draggingState = true;
  // other stuff
}

void OnDrag() {
  if(!_draggingState) return;
  // other stuff
}

void OnDragEnd() {
  if(!_draggingState) return;
  _draggingState = false;
  // other stuff
}

// implement this on your own, this is only an illustration
// you obviously need to meet certain conditions to re-enable dragging
// by checking for the appropriate ball parameters in update
void BallHasLandedAndIsInRest() {
  _draggingShouldWork = true;
}

Read more about the finite state machines (or FSM), this is one of the simplest possible. You need them a lot to control specific compound behaviors such as this. Thankfully this is only UI, and UI state machines tend to be really simple and thus usually bug-free. On the other end of the spectrum they can be so incredibly complex that you can’t approach them naively like this. Learn just the basic ropes of how to think about them, and learn about the relational and logical operators in C# so that you can write compound state evaluators with confidence.

In general, you want to make your code guarded by some switching mechanism like this one, so that the flow is always governed with a few simple states that you can easily keep track of. Just be mindful of the life cycle of each state: its purpose, when to begin, when to end; then there are certain parallel combinations between two or more switches, one state might affect the other state, some might get canceled etc. It can become hard to memorize in some cases, so try to draw a simple diagram before implementing it.

I am not able to understand can you please send me a modified code that will allow only to drag once?

I’m sorry, that’s the best I can do with your problem right now. It should be enough.

Thanks buddy after doing some experiments my code is working.