Unity
동적생성.
iRang1101
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)); } |