unity3d MouseLook 如何当单击左键移动鼠标才能实现上下左右全方位旋转
发布网友
发布时间:2022-05-02 03:05
我来回答
共3个回答
热心网友
时间:2023-10-09 06:24
在那个脚本前面加上一个判断就行了,if(Input.GetMouseButton(0)){ 旋转代码}追问具体应该加到哪里呢?我试了下,加了后运行不了。我把原代码补充到问题里你看看
追答你只把旋转的代码放到if里面就行
热心网友
时间:2023-10-09 06:24
public void LookRotation(Transform character, Transform camera)
{
if (Input.GetMouseButton (0))
{
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 (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;
}
}
}
热心网友
时间:2023-10-09 06:25
需要自己写代码控制旋转