public GameObject prefab;
public float w = 1;
public int n = 5;
public float spacing=1;
float c;
float r;
float ang;
public float dis;
public float cutSpeed=0.1f;
List<GameObject> list = new List<GameObject>();
List<Transform> sorts = new List<Transform>();
// Start is called before the first frame update
void Start()
{
c = (w + spacing) * n;
r = c / (2 * Mathf.PI);
ang = 2 * Mathf.PI / n;
Move();
}
public void Move()
{
float moveang = dis / r;
for (int i = 0; i < n; i++)
{
if(list.Count<=i)
{
list.Add(Instantiate(prefab));
list[i].AddComponent<PrefabDtop>().chart = this;
sorts.Add(list[i].transform);
}
float x = Mathf.Sin(i * ang + moveang) * r;
float z = Mathf.Cos
(i * ang + moveang) * r;
list[i].transform.position = new Vector3(x, 0, z);
}
}
public void Inertia(float endSpeed)
{
float time = Mathf.Abs(endSpeed / cutSpeed);
DOTween.To((float speed) =>
{
dis -= speed;
Move();
}, endSpeed, 0, time).OnComplete(()=>
{
Aling();
});
}
public void Aling()
{
sorts.Sort((a,b)=>
{
if(a.position.z<b.position.z)
{
return -1;
}
else if(a.position.z==b.position.z)
{
return 0;
}
else
{
return 1;
}
});
float moveang = Mathf.Asin(sorts[0].position.x / r);
float movedis = moveang * r;
float time = Mathf.Abs(movedis / cutSpeed);
DOTween.To((float enddis) =>
{
dis = enddis;
Move();
},dis,dis+movedis,time);
}
}
3D轮转图
最新推荐文章于 2023-09-13 11:01:21 发布