-
2021.03.20 - Unity - Mouse(object event)
Ex 눌려짐 감지
void Update() { // ... if (Input.GetButton("Fire1")) { Vector3 pos = Input.mousePosition; Debug.Log(" mose x:" + pos.x + " y:" + pos.y); } // ... }
Button 상태
GetButton
GetButtonDown
GetButtonUp
Button 종류
Fire1: 왼쪽 버튼, 또는 Ctrl
Fire2: 오른쪽 버튼, 또는 Alt
Fire3: 중간 버튼, 또는 Shift
Zoom In/Out
void Update() { if (Input.GetButton("Fire1")) { Ray ray = mCam.ScreenPointToRay(Input.mousePosition); mCam.transform.Translate(ray.direction * Time.deltaTime, Space.World); } if (Input.GetButton("Fire2")) { Ray ray = mCam.ScreenPointToRay(Input.mousePosition); mCam.transform.Translate(ray.direction * -Time.deltaTime, Space.World); } }
눌려진 Object 찾기
if (Input.GetButton("Fire1")) { RaycastHit hit; Ray ray = mCam.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { Transform objectHit = hit.transform; hit.transform.position = new Vector3(0,0,0); }
'Unity' 카테고리의 다른 글
Unity - Mouse (object event) (0) 2021.03.20 Unity - 3d object drag (0) 2021.03.20 Unity - Ray (0) 2021.03.19 Unity - Translate (0) 2021.03.18 Unity - Material (0) 2021.03.18 Unity - instantiate (GameObject 생성 함수) (0) 2020.11.17 Unity - UnityChan Transition(Animation) (0) 2020.11.16 Unity - UnityChan Model Improt (0) 2020.11.16