Unity3D

Unity 주요함수 #3

초코맛퐁듀 2014. 1. 16. 13:56

예1) Do 함수를 실행하고 그것이 완료된 후에 코드 실행을 계속함

function Start() {

// 자바스크립트의 경우, yield Do(); 와 같음

// C#의 경우, 반드시 StartCoroutine 사용해야 함

yield StartCoroutine(Do());

Debug.Log("This is printed after 5 seconds");

Debug.Log("This is after the Do corutine has finished execution");

}

 

function Do() {

Debug.Log("Do now");

yield WaitForSeconds(5);

Debug.Log("Do 5 Seconds later");

}

 

* 결과는

(1) Do now

(2) Do 5 Seconds later

(3) This is printed 5 sends

(4) This is after the Do coroutine has finished execution

 

예2) function Start() {

Debug.Log("Starting = " + Time.time);

yield WaitAndPrint();

 

Debug.Log("Done WaitAndPrint = " + Time.time);

}

 

function WaitAndPrint() {

yield WaitFor Seconds(5);

Debug.Log("WaitAndPrint = " + Time.time);

}

 

* 결과는

(1) Startine = 0

(2) WaitAndPrint = 5.003615

(3) Done WaitAndPrint = 5.003615

 

 

1. WaitForFixedUpdate

- FixedUpdate 함수의 다음번 호출을 기다림

예) function Start() {

// FixedUpdate가 끝나길 기다림

yield new WaitForFixedUpdate();

// FixedUpdate 호출이 끝나면 이어서...

Debug.Log("Call after FixedUpdate");

}

 

function FixedUpdate() {

Debug.Log("FixedUpdate");

}

 

[출처] 유니티 주요함수 #3 | 작성자 만듀