using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
//转动速度
public float speed = 5f;
//转动的位置
public float progress = 0;
//中心点
public Transform center;
//半径
public float radius = 1.5f;
private void Start()
{
}
void Update()
{
//transform.Translate(Vector3.forward * speed * Time.deltaTime);
progress += Time.deltaTime * speed;
if (progress >= 360)
{
progress -= 360;
}
float x1 = center.position.x + radius * Mathf.Cos(progress);
float y1 = center.position.y + radius * Mathf.Sin(progress);
//this.transform.position = new Vector3(x1, 0, y1);//横轴旋转
//this.transform.position = new Vector3(x1, y1,progress);//竖轴旋转
this.transform.position = new Vector3(x1, y1)+center.forward*progress;//竖轴旋转
}
}
效果类似下图