Files
tianrunCRM/Assets/CoolapeFrame/3rd/NGUI_Enhance/Examples/Scripts/Other/Spin.cs
2020-07-04 14:41:25 +08:00

53 lines
943 B
C#

using UnityEngine;
/// <summary>
/// Want something to spin? Attach this script to it. Works equally well with rigidbodies as without.
/// </summary>
[AddComponentMenu("NGUI/Examples/Spin")]
public class Spin : MonoBehaviour
{
public Vector3 rotationsPerSecond = new Vector3(0f, 0.1f, 0f);
public bool ignoreTimeScale = false;
Rigidbody mRb;
Transform mTrans;
void Start ()
{
mTrans = transform;
mRb = GetComponent<Rigidbody>();
}
void Update ()
{
if (mRb == null)
{
ApplyDelta(ignoreTimeScale ? RealTime.deltaTime : Time.deltaTime);
}
}
void FixedUpdate ()
{
if (mRb != null)
{
ApplyDelta(Time.deltaTime);
}
}
public void ApplyDelta (float delta)
{
delta *= Mathf.Rad2Deg * Mathf.PI * 2f;
Quaternion offset = Quaternion.Euler(rotationsPerSecond * delta);
if (mRb == null)
{
mTrans.rotation = mTrans.rotation * offset;
}
else
{
mRb.MoveRotation(mRb.rotation * offset);
}
}
}