- Home /
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.
Answer by DESTRUKTORR · Sep 02, 2012 at 02:35 PM
`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.
Answer by Graham-Dunnett · May 23, 2013 at 08:58 PM
http://docs.unity3d.com/Documentation/ScriptReference/Input.GetMouseButtonDown.html
"It will not return true until the user has released the mouse button and pressed it again."
You probably want GetMouseButton()
.
Answer by joel_b · May 23, 2013 at 08:59 PM
An example:
void Update ()
{
StartCoroutine(mouseDown());
}
IEnumerator mouseDown()
{
while(Input.GetMouseButton(0))
{
print("mouse button held down");
yield return null; // Give up control
}
}
Answer by Beru · Dec 27, 2013 at 03:08 AM
Be sure you move your mouse inside the game area, in the Game view.