Button On Click event firing GetMouseButton within script

So I have a button that runs a similar method as below when clicked, and the if statement is entered immediately but I’m wanting this if statement to be entered when the user clicks again after initially pressing the button, how can this be done?

public void ButtonCommand()
{
     while(true)
     {
          if (Input.GetMouseButtonDown(0))
          {
               //do something
          }
     }
}

Hello @eddlilley. You can simply achive what you want by setting a bool. Try something like this:

private bool enableSecondClick = false;

public void Update()
{
    if (enableSecondClick == true)
    {
        if (Input.GetMouseButtonDown(0))
        {
            // do something

            // if you want this scenario to happen more than once, you can set the bool back to false
            enableSecondClick = false;
        }
    }
}

public void ButtonCommand()
{
    enableSecondClick = true;
}

Let me know if it worked.

All the best :slight_smile:

@tmalhassan sorry I should have made it clear, the users second click can be anywhere on screen, not hitting the same button again.