不能穿统一侧



我想做一款fps游戏。为了创建第一人称查看器,我遵循了youtube

我按照他说的去做,我可以成功地向上或向下看,但不能向旁边看。

代码如下:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class mouselook : MonoBehaviour
{
float mousesenitivevity = 100f;
public Transform player_eyes;
float xRotation = 0f;
// Start is called before the first frame update
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void Update()
{
float mouseX = Input.GetAxis("Mouse X") * mousesenitivevity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mousesenitivevity * Time.deltaTime;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
player_eyes.Rotate(Vector3.up * mouseX);
}
}

我真的不知道错误发生在哪里,但这里有一些我注意到的事情:

如果你注释掉了transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);行,那么玩家只能看侧面而不能看上下,如果你取消注释,玩家只能看上下而不能看侧面。

以下是unity编辑器的截图:编辑图片

解决了,我把脚本错误地放在播放器上而不是相机上。

最新更新