2016-10-22 5 views
0

저는 GameObject를 가지고 있으며 특정 시간대에 축소해야합니다.특정 시간대에 GameObject의 크기를 변경하십시오.

내 GameObject의 크기가 근본적으로 100x100이므로 정확히 1 초 안에 10x10으로 축소하고 싶습니다.
이제 InvokeRepeating을 사용할 수는 있지만 100x100에서 10x10으로 점프합니다.
100x100에서 10x10으로 원활하게 이동하고 싶습니다.
코드가 아직 없습니다. Update을 사용하면 올바른 결과를 얻지 못하기 때문에 어떻게 수행되는지 알아 내려고합니다.

+1

https://docs.unity3d.com/ScriptReference/Mathf.Lerp.html –

답변

0

while 루프에서 CoroutineVector.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)); 
} 
관련 문제