FPSCaracterController旋轉由包含其資產的MouseLook.cs腳本驅動。 如果你打開它,你會看到,控制旋轉的功能:
public void LookRotation(Transform character, Transform camera)
此方法會修改旋轉值直接用鼠標沒有任何中間操作的價值。所以,如果你想改變FPController的旋轉,你需要修改這個方法(或這個類)
例如,我做了這個修改使得FPController每次旋轉180度時用戶按下「U」鍵:
public void LookRotation(Transform character, Transform camera)
{
float yRot = CrossPlatformInputManager.GetAxis("Mouse X") * XSensitivity;
float xRot = CrossPlatformInputManager.GetAxis("Mouse Y") * YSensitivity;
m_CharacterTargetRot *= Quaternion.Euler(0f, yRot, 0f);
m_CameraTargetRot *= Quaternion.Euler(-xRot, 0f, 0f);
if (ORPargaModification)
{
if(Input.GetKeyDown(KeyCode.U))
{
Debug.Log("U pressed");
m_CharacterTargetRot *= Quaternion.Euler(0f, 180, 0f);
}
character.localRotation = m_CharacterTargetRot;
camera.localRotation = m_CameraTargetRot;
}
else
{
if (clampVerticalRotation)
m_CameraTargetRot = ClampRotationAroundXAxis(m_CameraTargetRot);
if (smooth)
{
character.localRotation = Quaternion.Slerp(character.localRotation, m_CharacterTargetRot,
smoothTime * Time.deltaTime);
camera.localRotation = Quaternion.Slerp(camera.localRotation, m_CameraTargetRot,
smoothTime * Time.deltaTime);
}
else
{
character.localRotation = m_CharacterTargetRot;
camera.localRotation = m_CameraTargetRot;
}
}
UpdateCursorLock();
}
Google FPS Controller Script ... http://answers.unity3d.com/questions/700918/how-to-get-my-camera-to-follow-first-person-pov-in。 html –