Files
MRArcadia/Assets/_Arcadia/Scripts/Common/AutoRotate.cs
2026-03-24 11:25:32 +08:00

41 lines
1.2 KiB
C#

using UnityEngine;
/// <summary>
/// 自动旋转组件 - 物体沿Y轴自动旋转
/// </summary>
public class AutoRotate : MonoBehaviour
{
[Header("旋转设置")]
public float rotationSpeed = 30f; // 旋转速度(度/秒)
public bool rotateX = false; // 是否沿X轴旋转
public bool rotateY = true; // 是否沿Y轴旋转
public bool rotateZ = false; // 是否沿Z轴旋转
public Space rotationSpace = Space.Self; // 旋转空间(自身/世界)
[Header("调试")]
public bool debugMode = false;
private void Update()
{
// 构建旋转向量
Vector3 rotation = Vector3.zero;
if (rotateX)
rotation.x = rotationSpeed * Time.deltaTime;
if (rotateY)
rotation.y = rotationSpeed * Time.deltaTime;
if (rotateZ)
rotation.z = rotationSpeed * Time.deltaTime;
// 应用旋转
if (rotation != Vector3.zero)
{
transform.Rotate(rotation, rotationSpace);
}
if (debugMode)
{
Debug.Log($"[AutoRotate] 当前旋转: {transform.eulerAngles}");
}
}
}