반응형
private Vector2 movePosDiff;
private enum MouseState { Begin, Moved, Cancel }
private MouseState mouseState = MouseState.Cancel;
private float mouseDragSpeed = 3f;
void Update() {
RotateCamera( GetMouseDragValue() );
}
private void RotateCamera(Vector2 diff) {
Vector3 nextEulerAngles = mainCamera.transform.rotation.eulerAngles;
nextEulerAngles.y -= diff.x * mouseDragSpeed;
mainCamera.transform.rotation = Quaternion.Euler(nextEulerAngles);
}
private Vector2 GetMouseDragValue() {
movePosDiff = Vector3.zero;
if(Input.GetMouseButtonDown(0)) {
if(mouseState == MouseState.Cancel) {
mouseState = MouseState.Moved;
}
}
if(Input.GetMouseButtonUp(0)) {
mouseState = MouseState.Cancel;
}
if(mouseState == MouseState.Moved) {
Debug.Log($"#### Moved ({Input.GetAxis("Mouse X")}, {Input.GetAxis("Mouse Y")})");
movePosDiff = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
}
return movePosDiff;
마우스로 화면 끌어서 회전 POC
반응형
'Unity > Unity 리서치' 카테고리의 다른 글
VS Code C# 생성자 자동생성 (1) | 2021.08.08 |
---|---|
내부 클래스를 인스펙터 창이 노출 (0) | 2021.07.31 |
CameraShake (카메라 흔들기) (0) | 2021.07.26 |
Animation Override Controller (0) | 2021.07.17 |
Canvas와 World좌표 연동 (Camera.WorldToScreenPoint) (0) | 2021.07.16 |