void CheckTouchStart() { if (!canRotate) { return; } Vector2 inputPos = Utility.getTouchStart(); if (inputPos == Vector2.zero) { return; } var ray = Camera.main.ScreenPointToRay(inputPos); RaycastHit hit; var doesHit = handleCollider.Raycast(ray, out hit, Mathf.Infinity); if (!doesHit) { return; } startVector = GetTouchDirFromPlaneCenter(inputPos); phase = RotationPhase.Move; onRotationStart.Invoke(); }
void OnTouchMove() { var inputPos = Utility.getTouchEnd(); if (inputPos == Vector2.zero) { inputPos = Utility.getTouch(); } else { phase = RotationPhase.Idle; onRotationDone.Invoke(); return; } var currVector = GetTouchDirFromPlaneCenter(inputPos); if (startVector != currVector) { print(currVector); } var angle = Vector3.SignedAngle(startVector, currVector, -handler.up); onRotationMove.Invoke(angle); }
public void Patrolling(){ float myAngleY = transform.rotation.eulerAngles.y; switch(myRotPhase){ case RotationPhase.Phase1: rotateNegative = false; if (myAngleY > trueMaxRotLimit) { myRotPhase = RotationPhase.Phase2; } break; case RotationPhase.Phase2: if (myAngleY < trueMinRotLimit) { rotateNegative = true; } else{ myRotPhase = RotationPhase.Phase3; } break; case RotationPhase.Phase3: if (myAngleY > trueMinRotLimit) { rotateNegative = true; } else { myRotPhase = RotationPhase.Phase4; } break; case RotationPhase.Phase4: if (myAngleY > trueMaxRotLimit) { rotateNegative = false; } else { myRotPhase = RotationPhase.Phase1; } break; } if (!rotateNegative) { transform.Rotate (Vector3.up, Time.deltaTime * rotationSpeed); } else { transform.Rotate (-Vector3.up, Time.deltaTime * rotationSpeed); } }