Trick or True
[Unity] Instantiate() 함수 본문
Object.Instantiate :
Clones the object original and returns the clone.
게임 Object나 Prefab의 복사본을 생성한다. 주로 게임 플레이 중 총알, 적, 아이템 등을 동적으로 생성할 때 사용된다.
// 기본
GameObject clone = Object.Instantiate(prefab);
// 위치와 회전을 지정해 생성
GameObject clone = Object.Instantiate(prefab, position, rotation);
// 부모 transform을 지정해 생성
GameObject clone = Object.Instantiate(prefab, parentTransform);
// 위치, 회전, 부모 transform 모두 지정해 생성
GameObject clone = Object.Instantiate(prefab, position, rotation, parentTransform);
예시
if (Input.GetKeyDown(KeyCode.Space))
{
//Launch a projectile from the player
Instantiate(projectilePrefab, transform.position, projectilePrefab.transform.rotation);
}
'게임 개발' 카테고리의 다른 글
| [Unity]InvokeRepeating (1) | 2024.11.08 |
|---|---|
| [Unity] projection(투영) (0) | 2024.11.08 |
Comments