【发布时间】:2018-04-21 18:46:04
【问题描述】:
如何停止角色在 y 轴上的相机转动和倾斜?我的意思是我希望能够在不改变玩家位置的情况下向上和向下看。可以让它在 x 轴(左右)上转动。 代码如下:
using UnityEngine;
using System.Collections;
public class Actions : MonoBehaviour
{
public float speedH = 2.0f;
public float speedV = 2.0f;
private float yaw = 0.0f;
private float pitch = 2.0f;
private void Update()
{
yaw += speedH * Input.GetAxis("Mouse X");
pitch = Input.GetAxis("Mouse Y");
pitch = Mathf.Clamp(pitch, -30f, 45f);
transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);
}
private void Start()
{
}
}
【问题讨论】:
-
这真的是您当前的代码吗?我认为这不会编译。你有两次
Update函数。如果您不想绕 x 轴旋转,则删除音高代码并将 x 轴替换为 0。 -
remove the pitch code and replace x axis with 0.正如程序员所说。