Input.GetMouseButtonDown(0) not work properlly

Hi everyone,

Cant figure out why it doesn’t work as expected. this a part of script.

function Update(){
	print(Input.GetMouseButtonDown(0));
}

Well, it returns true only, when I press button, but it returns false even i still hold button down.

GetMouseButtonDown, GetButtonDown, and GetKeyDown all only call once, for the event of actually pressing the mouse button/button/key. The same goes for GetMouseButtonUp, GetButtonUp, and GetKeyUp with respect to releasing said mouse button/button/key.

GetMouseButton, GetButton, and GetKey call continuously, as the mouse button/button/key are held down.

Look here for more information on how to use the Input class.

“It will not return true until the user has released the mouse button and pressed it again.”

You probably want GetMouseButton().

An example:

 void Update ()
    {
        StartCoroutine(mouseDown());
    }
     
    IEnumerator mouseDown()
    {
        while(Input.GetMouseButton(0))
        {
           print("mouse button held down");
           yield return null;  // Give up control  
        }
    }

Be sure you move your mouse inside the game area, in the Game view.