while 루프에서 Coroutine
및 Vector.Lerp
으로 수행 할 수 있습니다. 이것은 Invoke
또는 InvokeRepeating
기능을 사용하는 것보다 낫습니다.
bool isScaling = false;
IEnumerator scaleOverTime(GameObject objToScale, Vector3 newScale, float duration)
{
if (isScaling)
{
yield break;
}
isScaling = true;
Vector3 currentScale = objToScale.transform.localScale;
float counter = 0;
while (counter < duration)
{
counter += Time.deltaTime;
Vector3 tempVector = Vector3.Lerp(currentScale, newScale, counter/duration);
objToScale.transform.localScale = tempVector;
yield return null;
}
isScaling = false;
}
사용 :
public GameObject gameObjectToScale;
void Start()
{
StartCoroutine(scaleOverTime(gameObjectToScale, new Vector3(2, 2, 2), 1f));
}
https://docs.unity3d.com/ScriptReference/Mathf.Lerp.html –