using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class movelimit : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (transform.localEulerAngles.z != 0)
{
float rotX = transform.localEulerAngles.x;
float rotY = transform.localEulerAngles.y;
transform.localEulerAngles = new Vector3(rotX, rotY, 0);
}
}
}
本文介绍了一个Unity脚本,用于限制游戏物体在运动过程中的旋转角度,确保物体不会发生不必要的旋转,保持其方向稳定。通过读取物体当前的旋转角度,并在每帧更新时将Z轴的角度强制设置为0,实现物体在X和Y轴上的自由旋转,同时阻止Z轴旋转。
8291

被折叠的 条评论
为什么被折叠?



