You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.4 KiB
55 lines
1.4 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class PointMoveCtr : MonoBehaviour
|
|
{
|
|
//이펙트 이동 기준 오브젝트
|
|
public Transform pointsParent;
|
|
//시작 점 번호
|
|
public int startPoint;
|
|
//한바퀴 도는데 걸리는 시간
|
|
public float loopTime;
|
|
|
|
private List<Transform> cornerPointList = new List<Transform>();
|
|
|
|
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());
|
|
}
|
|
}
|