using System.Collections; using System.Collections.Generic; using UnityEngine; public class PointMoveCtr : MonoBehaviour { //이펙트 이동 기준 오브젝트 public Transform pointsParent; //시작 점 번호 public int startPoint; //한바퀴 도는데 걸리는 시간 public float loopTime; private List cornerPointList = new List(); void Awake() { for(int i = 0; i < pointsParent.childCount; i++) { cornerPointList.Add(pointsParent.GetChild(i)); } } void OnEnable() { StartCoroutine(EffectMove()); } private IEnumerator EffectMove() { if (cornerPointList.Count == 0) yield break; transform.localPosition = cornerPointList[startPoint].localPosition; int nextPoint = startPoint + 1; if (nextPoint >= cornerPointList.Count) nextPoint = 0; float time = loopTime / cornerPointList.Count; float runTime = time; while (runTime > 0f) { transform.localPosition = Vector3.Lerp(cornerPointList[startPoint].localPosition, cornerPointList[nextPoint].localPosition, (time - runTime) / time); yield return null; runTime -= Time.unscaledDeltaTime; } startPoint++; if (startPoint >= cornerPointList.Count) startPoint = 0; StartCoroutine(EffectMove()); } }