J's Study log

[Unity] Input Mouse Button 본문

Computer Language/Unity

[Unity] Input Mouse Button

정우섭 2019. 2. 27. 01:34

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.

'Computer Language > Unity' 카테고리의 다른 글

[Unity] Local Transform  (0) 2019.02.27
[Unity] Parents and Child Object  (0) 2019.02.27
[Unity] Input keys  (0) 2019.02.25
[Unity] Input Arrow Keys  (0) 2019.02.25
[Unity] Camera Work  (0) 2019.02.25
Comments