[Unity] Input Mouse Button
Just like Key Input the mouse button have commands like
Input.GetMouseButton(num) - Will continue to happen while you are holding mouse button.
Input.GetMouseButtonDown(num) - Will happen when you hit mouse button.
Input.GetMouseButtonUp(num) - Will happen when you release mouse button.
['num' can be 0(Left Mouse Button) or 1(Right Mouse Button or 2(Central Mouse Button)]
Example code
void Update () {
if (Input.GetMouseButton(0))
{
Debug.Log("left mousebutton");
}
if (Input.GetMouseButtonDown(0))
{
Debug.Log("left mousebutton down");
}
if (Input.GetMouseButtonUp(0))
{
Debug.Log("left mousebutton up");
}
}
And let's find out how to make an event happens, when the mouse clicks specific place. The command is
Input.mousePosition - Reports the position of the mouse even when it is not inside the Game View, such as when Cursor.lockState is set to CursorLockMode.None. When running in windowed mode with an unconfined cursor, position values smaller than 0 or greater than the screen dimensions (Screen.width, Screen.height) indicate that the mouse cursor is outside of the game window.