This commit is contained in:
2020-07-04 14:41:25 +08:00
parent 70c346d2c1
commit a8f02e4da5
3748 changed files with 587372 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
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);
}
}
}