我知道Google中有一些答案,但是我不能用以下代码来限制轮换:
element {pointer-events:auto}
我希望在 X 轴上的范围从 0 到 90 。
谢谢!
答案 0 :(得分:0)
使用四元数代替。
public Vector3 rotation;
private GameObject go;
private void Start()
{
go = GameObject.CreatePrimitive(PrimitiveType.Cube);
}
void Update()
{
go.transform.rotation = Quaternion.Euler(Mathf.Clamp(rotation.x, 0, 90),
rotation.y, rotation.z);
}
public class CameraClamp : MonoBehaviour
{
public float speed;
public Vector2 clamp; // x = min, y = max
private float pitch;
private void Update()
{
pitch += Input.GetAxis("Mouse Y") * speed * Time.deltaTime;
//pitch -= Input.GetAxis("Mouse Y") * speed * Time.deltaTime; // Invert
pitch = Mathf.Clamp(pitch, clamp.x, clamp.y);
}
private void LateUpdate()
{
gameObject.transform.rotation = Quaternion.Euler(pitch, 0, 0);
}
}