【发布时间】:2016-12-15 01:34:16
【问题描述】:
我在 Unity3d 上有一个游戏,我想通过脚本旋转玩家对象:
Camera.main.transform.Rotate(0, 10, 0);
我无法旋转玩家对象,所以我尝试使用相机组件旋转它的子对象。而且我只能在标准脚本MouseLook.cs中注释2个字符串时才能做到这一点:
[Serializable]
public class MouseLook
{
// Variables ..
private Quaternion m_CharacterTargetRot;
private Quaternion m_CameraTargetRot;
public void Init(Transform character, Transform camera)
{
m_CharacterTargetRot = character.localRotation;
m_CameraTargetRot = camera.localRotation;
}
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(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; // move y axe
//camera.localRotation = m_CameraTargetRot; // move x axe
}
}
}
但是当我评论它时,当我移动它时,我的鼠标没有反应。我该如何解决?
【问题讨论】: