Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

GUMI Dev

[유니티 Input] 마우스 입력 본문

Unity

[유니티 Input] 마우스 입력

GUMI Dev 2021. 11. 17. 02:57

GetMouse: 마우스 버튼 입력을 받으면 true

* GetMouse는 안에 들어가는 매개변수를 숫자(0 또는 1)로 받는다.

* Input.GetMouseButton(0) 혹은 Input.GetMouseButton(1)과 같은 방식으로 표현한다. 

* 여기서 0은 마우스 왼쪽 버튼이며 1은 마우스 오른쪽 버튼이다. 

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LifeCycle : MonoBehaviour
{
    void Update()
    {
        {
            if (Input.anyKeyDown)
                Debug.Log("플레이어가 아무 키를 눌렀습니다. ");

            if (Input.GetMouseButtonDown(0))
                Debug.Log("미사일 발사!");

            if (Input.GetMouseButton(0))
                Debug.Log("미사일 모으는 중");

            if (Input.GetMouseButtonUp(0))
                Debug.Log("슈퍼 미사일 발사");
        }
    }
}

 

마우스 왼쪽 버튼을 클릭하면서 실행해보았다.