如何在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()
{
}
}
答案 0 :(得分:0)
我会创建一个空的游戏对象并将相机作为其父级。然后我会使用脚本将obj移动到玩家的位置,然后根据鼠标输入轴旋转obj。