36 lines
791 B
C#
36 lines
791 B
C#
using UnityEngine;
|
|
|
|
namespace Kirurobo {
|
|
/// <summary>
|
|
/// 使附加的对象以恒定速度进行偏航旋转
|
|
/// </summary>
|
|
public class AutoRotator : MonoBehaviour {
|
|
/// <summary>
|
|
/// 旋转速度 [度/秒]
|
|
/// </summary>
|
|
public float angularVelocity = 90f;
|
|
|
|
/// <summary>
|
|
/// 旋转轴(偏航旋转,方向向上)
|
|
/// </summary>
|
|
Vector3 rotationAxis = Vector3.up;
|
|
|
|
/// <summary>
|
|
/// 初始姿态
|
|
/// </summary>
|
|
Quaternion initialLocalRotation;
|
|
|
|
// 用于初始化
|
|
void Start () {
|
|
// 记录初始姿态
|
|
initialLocalRotation = transform.localRotation;
|
|
}
|
|
|
|
// 每帧调用 Update
|
|
void Update () {
|
|
var rotation = Quaternion.Euler(0f, Time.time * angularVelocity, 0f);
|
|
transform.localRotation = initialLocalRotation * rotation;
|
|
}
|
|
}
|
|
}
|