-
[Unity] 멀티터치(2개)를 통한 오브젝트 회전Unity 2023. 11. 21. 14:42
저장용..
bool rotating; Vector2 startVector; float rotGestureWidth; float rotAngleMinimum; if (Input.touchCount == 2) { Touch touch1 = Input.GetTouch(0); Touch touch2 = Input.GetTouch(1); // 배치할 오브젝트 회전 if (!rotating) { startVector = touch2.position - touch1.position; rotating = startVector.sqrMagnitude > rotGestureWidth * rotGestureWidth; } else { var currVector = Input.GetTouch(1).position - Input.GetTouch(0).position; var angleOffset = Vector2.Angle(startVector, currVector); //외적을 통해 방향 구분 var LR = Vector3.Cross(startVector, currVector); if (angleOffset > rotAngleMinimum) { if (LR.z > 0) { //반시계방향 회전, 내적을 통해 돌리는데 필요한 Power 설정 var angleP = Vector3.Angle(startVector, currVector); Item = transform.rotation = Quaternion.Euler(0.0f, -angleP, 0.0f); } else if (LR.z < 0) { //시계방향 회전, 내적을 통해 돌리는데 필요한 Power 설정 var angleP = Vector3.Angle(startVector, currVector); Item = transform.rotation = Quaternion.Euler(0.0f, angleP, 0.0f); } } } } else { rotating = false; }출처: https://forum.unity.com/threads/rotation-gesture.87308/
Rotation gesture
Hi, does anyone have or know where to find rotation gesture script? I don't need to rotate and object etc, just to detect that rotation gesture...
forum.unity.com
'Unity' 카테고리의 다른 글
[Unity] ScrollView와 EventTrigger (1) 2024.03.15 [Unity] UI Image의 Vertex를 드래그하여 다각형 그리기(feat. BaseMeshEffect) (0) 2023.11.22 [Unity] 소소한 Tip 모음 (주기적 업데이트) (4) 2023.11.21