can't change bool in update function

public void Launch()
{
OnclickButton = true;
Debug.Log(OnclickButton+“On Call”);
}
// Update is called once per frame
void Update()
{
if (!HasStarted)
{
LockOnPaddle();
}
}

public void LockOnPaddle()
{
    if(OnclickButton == true)
    {
        Debug.Log(OnclickButton + "inside fucntion");
        LaunchOnClick();
    }
    else if(OnclickButton == false)
    {
        Vector2 PaddlePos = new Vector2(paddle1.transform.position.x, paddle1.transform.position.y);
        transform.position = PaddlePos + MouseToPaddlePos;
    }
}

public void LaunchOnClick()
{ 
    FindObjectOfType<Ball>().GetComponent<Rigidbody2D>().velocity = new Vector2(LaunchX, LaunchY);
    HasStarted = true;
}

Here i’m making a ui button onclick call to Launch(), which changes the onClickbutton to true so according to function the debug is printed on console, but inside the LockOnPaddle function only the else condition is active , what am i missing here why the LaunchOnClick() function isn’t getting called???
I can’t get the Lockonpaddle out of update as it keeps the ball on paddle but the ball isn’t launching. Please can someone help me with this … thanks in advance.

What’s happening is that you are getting the event call, your OnclickButton variable is being set to true, as you expect.

However, what happens is that inside LockOnPaddle(), you are for one brief moment getting into the true condition of your if() statement, when then calls LaunchOnClick().

This is where the problem occurs. Inside LaunchOnClick(), you set the value of HasStarted to ‘true’. Now, the next time your Update() gets called, the if (!HasStarted) returns false, and your LockOnPaddle() is called Nevermore.