懒得写了,直接上代码
public class Rotate : MonoBehaviour
{
public GameObject target;
public GameObject m_this;
public float speed = 100;
float progress = 0;
float distance = 0;
public float x = 5;
public float z = 7;
private void Awake()
{
distance = Vector3.Distance(target.transform.position, m_this.transform.position);
}
private void Update()
{
OvalRotate();
}
//绕圆形旋转
void RoundnessRotate()
{
progress += Time.deltaTime*speed;
Vector3 p = new Vector3(Mathf.Cos(progress * Mathf.Deg2Rad), 0, Mathf.Sin(progress * Mathf.Deg2Rad)) * distance;
m_this.transform.position = target.transform.position + p;
}
//绕椭圆形旋转
void OvalRotate()
{
progress += Time.deltaTime * speed;
Vector3 p = new Vector3(x * Mathf.Cos(progress * Mathf.Deg2Rad), 0,z* Mathf.Sin(progress * Mathf.Deg2Rad)) * distance;
m_this.transform.position = target.transform.position + p;
}
}