using UnityEngine;
using System.Collections;
public class RotateParticle : MonoBehaviour {
[SerializeField]
private float delay = 0f;
[SerializeField]
bool loop = false;
[SerializeField]
float speed = 1f;//one loop time
[SerializeField]
bool direction = true;
[SerializeField]
ERoateAround around;
float rotateBeginTime;
Quaternion originAngle;
Quaternion targetAngle;
float rotated = 0f;
enum ERoateAround
{
Forward,
Right,
Up
}
// Use this for initialization
void Start()
{
rotateBeginTime = Time.time + delay;
originAngle = transform.rotation;
//targetAngle = Quaternion.ro
}
// Update is called once per frame
void Update()
{
if(rotateBeginTime < Time.time)
{
float angle = speed * (direction ? 1 : -1);
transform.Rotate(GetAround(), angle, Space.Self);
rotated += speed;
if (rotated >= 360f && loop == false)
{
enabled = false;
}
}
}
private Vector3 GetAround()
{
if(around == ERoateAround.Forward)
{
//return transform.forward;
return Vector3.forward;
}else if(around == ERoateAround.Right)
{
//return transform.right;
return Vector3.right;
}else
{
//return transform.up;
return Vector3.up;
}
}
}
使用很简单,挂节点上就可以用了
目前默认是本地坐标系的旋转
后续有空(如果我能克服拖延症的话)更新一版同时支持世界和本地坐标系的
开源是一种精神