Unity -- 玩家的相机 Child 无法控制地旋转

Unity -- Camera Child of Player Rotates Uncontrollably

我有一个摄像机,我想一直和玩家保持在同一个位置。我通过将其设为玩家的 child 来做到这一点,因为当我通过脚本执行此操作时,玩家会领先于镜头。我也有用鼠标旋转的相机。但是,当我将相机设为播放器的 child 时,我的播放器和相机现在不会停止旋转,而是在鼠标静止时继续旋转。我希望相机仅在鼠标移动时旋转。我的代码 (JS):

    #pragma strict
var player : GameObject;
function Start () {
    player = GameObject.Find("Player");
    Cursor.visible = false;
}

function Update () {
    //transform.position = player.transform.position;
    transform.Rotate(Input.GetAxis("Mouse Y") * -2, Input.GetAxis("Mouse X") * 5, 0);
    transform.rotation.eulerAngles = new Vector3(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, 0);
    //player.transform.rotation = transform.rotation;
}

注释掉的第一行是 now-unnecessary 将相机移动到播放器的代码,第二行是导致问题的代码。如果我删除它,相机可以正常旋转但播放器无法转动(transform.forward-based 控件)。如果我取消注释,播放器和相机转动时没有摩擦,无法控制。

这并不是制作鼠标外观控制器的真正方式。 您应该看看这些控制器:

https://forum.unity.com/threads/a-free-simple-smooth-mouselook.73117/

http://wiki.unity3d.com/index.php/SmoothMouseLook

或者这个 JS 之一:http://answers.unity3d.com/answers/367253/view.html