'onmousedown'에 해당되는 글 1건

  1. 2018.03.18 [유니티] 마우스 클릭 관련 함수 Input.GetMouseButtonDown & OnMouseDown 3

- Input.GetMouseButtonDown : 마우스 버튼을 누른 순간


뒤에 소괄호 안에 숫자 0, 1, 2에 따라 마우스 왼쪽버튼, 오른쪽버튼, 휠버튼으로 나뉜다.


누른 순간 true로 변환되며, 아무것도 안 했을 때 기본적으로 false로 구분됨. 


using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void Update() { if (Input.GetMouseButtonDown(0)) Debug.Log("Pressed left click."); if (Input.GetMouseButtonDown(1)) Debug.Log("Pressed right click."); if (Input.GetMouseButtonDown(2)) Debug.Log("Pressed middle click."); } }

OnMouseDown() 보다는 Input.GetMouseButtonDown()을 추천한다.


그 이유는 



    void OnMouseDown()
    {
        print("OnMouseDown~~");
    }

    void Update () {
        if (Input.GetMouseButtonDown(0))
        {
        print("Input.GetMouseButtonDown!!");
        }
    }


이렇게 하고 실행을 해보니, 이유는 모르겠으나 


Input.GetMouseButtonDown!!만 게속 출력되고, OnMouseDown은 실행이 되지 않는다.


또한,


OnMouseDown() 함수는 모바일에서 적용되지 않는다.

 

Posted by sungho88
,