동적생성.

Unity 2015. 8. 18. 19:44


적, 혹은 총탄을 생성할때... 

prefab으로 한다. ... 



 함수의 멤버 변수로 prefab를 만들다.

 필요할때.. Instantiate해준다. 



public GameObject obj;

//( obj : 복사될 gameObject,  Vector2 : 생성될 위치, Quaternion : 생성되었을 때의 회전 )

Instantiate(obj, new Vector2(-2,-2), Quaternion.identity );






반복 생성시... 코루틴 사용. invoke()로 사용해도 될려나??? 타이머라는데...



StartCoroutine (objectGenerator (0.5f));


IEnumerator objectGenerator (float waitTime)

{

yield return new WaitForSeconds(waitTime);

Instantiate(obj, new Vector2(-2,-2), Quaternion.identity );

StartCoroutine (objectGenerator (1.0f));

}



'Unity' 카테고리의 다른 글

화면전환.  (0) 2015.11.09
change sprite  (0) 2015.08.18
save/load data  (0) 2015.08.04
InputField의 입력 받아 처리할때.. (end edit)  (0) 2015.08.04
폴더 이름 규칙  (0) 2015.07.29
Posted by iRang1101
,