Unity 3D 实现第一人称视角
思路:第一人称的视角移动最关键的就是对摄像机的操作了吧。首先一个就是灵敏度的设置。其次就是转的速度。
public class xiangji : MonoBehaviour
{
private float x, y;//坐标x与y
private float lingmindu;//灵敏度
private float rotax, rotay;//旋转
// Start is called before the first frame update
void Start()
{
lingmindu = 2f;//灵敏度为2
}
// Update is called once per frame
void Update()
{
x = Input.GetAxis("Mouse X");//鼠标的获取x坐标值
y = Input.GetAxis("Mouse Y");//鼠标的获取y坐标值
rotax += x * lingmindu;//获取变化值;
rotay -= y * lingmindu;//鼠标向上,视角却向下
rotay = Mathf.Clamp(rotay, -90, 90);//里面(物体,最小值,最大值)
transform.eulerAngles = new Vector3(rotay, rotax, 0);//水平旋转绕y轴;垂直旋转绕x轴
}
}