c# 강의/유니티

20200508 - 프리팹

쪼혀 2020. 5. 8. 15:53

> GameObject 가 파일화 된 것

 

 

 

클론 프리팹 연결 해제

 

폴더 이름 대소문자 까지 같아야함 위치는 상관없음

 

Prefabs 폴더 생성

 

 


> 리소스 불러오기

public GameObject heroPrefab;

void Start(){
this.heroPrefab =  Resources.Load("Prefabs/ch_01_01") as GameObject;
        Debug.Log(this.heroPrefab);
        
        }

 

 

 


 

 

1. prefab을 로드 한다(Hero, ch_01_01 )

-> Resources.Load(경로) 확장자 제외 Assets/Resources 까지 상위 폴더 경로 필요

    Resources.Load(경로) as GameObject;

-> Resources.Load<GameObject>(path) 가능하다.

 

2. Hero 프리팹을 Instantiate 한다 -> Hero 프리팹의 Clone게임오브젝트 생성됨.

 

3. Hero컴포넌트를 부착

  ->  this.heroPrefab.AddComponent<Hero>();

 

4. Model(ch_01_01) 프리팹을 Instantiate 한다

-> ch_01_01 프리팹의 Clone 게임오브젝트 생성됨

 

5. ch_01_01게임 오브젝트(Clone)의 부모로 Hero 게임 오브젝트 (Clone) 를 설정

 this.transform.SetParent(paransfrom);

this.transform.SetParent(paransfrom, false);