Mouse click is detected twice

I’m trying to detect two different mouse click but only a single mouse click is detected twice, I don’t know whats wrong with the code but I can’t detect two separate mouse clicks

bool click = true;
void Update()
{
        if(click)
        {
     	        if(Input.GetMouseButton(0))
            	{
	        	   print ("Click1");
		           click = false;
	            }
        }
        else
	    {
		        if(Input.GetMouseButton(0))
		        {
			       print ("Click2");
		        }
	    }
}

On single mouse click, I got “Click2”, it should be giving “Click1”, can anyone explain why I’m getting “Click2” on first mouse click

Edit: copy paste, “update()” function mistake corrected to “Update()”

‘update()’ with a lower case ‘u’ will not work. As for your issue, Input.GetMouseButton(), returns true for every frame the button is held down. It can easily return true for multiple frames. You want to use Input.GetMouseButtonDown() or InputGetMouseButtonUp(). Here is a bit of a rewrite to your logic:

using UnityEngine;
using System.Collections;
 
public class Bug27 : MonoBehaviour {
	bool click = true;
	void Update()
	{
	    if(click)
	    {
	            if(Input.GetMouseButtonDown(0))
	            {
	              Debug.Log ("Click1");
	              click = false;
	            }
	    }
	    else
	    {
	           if(Input.GetMouseButtonDown(0))
	           {
	            Debug.Log ("Click2");
				    click = true;
	           }
	    }
	}
}