1、左右旋转
float RotationX = Input.GetAxis("Mouse X") * Speed;//Speed=2
float rotatedAngle = camera.transform.localRotation.eulerAngles.y + RotationX ;//旋转角度小于15则设置为15
if (rotatedAngle < 15)
{
camera.transform.RotateAround(player.position, camera.transform.right, RotationX + (15 - rotatedAngle));
}
else if (rotatedAngle > 85) //旋转角度大于85则设置85
{
camera.transform.RotateAround(player.position, camera.transform.right, RotationX - (rotatedAngle - 85));
}
else
{
camera.transform.RotateAround(player.position, camera.transform.right, RotationX );
}
2、上下旋转
float RotationY = -Input.GetAxis("Mouse Y") * Speed;//speed=2
float RotationY1 = camera.transform.localRotation.eulerAngles.x + RotationY;
if (RotationY1 > 45 && RotationY > 0)
{
camera.RotateAround(Vector3.zero, camera.right, RotationY - (RotationY1 - 45));
}
else if (RotationY1 < 10 && RotationY < 0)
{
camera.RotateAround(Vector3.zero, camera.right, RotationY + (10 - RotationY1));
}
else
{
camera.RotateAround(Vector3.zero, camera.right, RotationY);
}
网友评论