1026 Resources.Load 함수로 에셋 로드하기

null·2023년 10월 26일

Unity Study

목록 보기
29/60
  1. 에셋 폴더에 'Resources' 폴더 생성

  2. Resources 폴더에 에셋 집어넣기

  3. 넣은 에셋 불러오기

예시:

void Start()
{
	GameObject cube = Resources.Load<GameObject>("Cube");
}
  1. 하위 폴더를 생성하여 불러오기도 가능
void Start()
{
	GameObject cube = Resources.Load<GameObject>("Prefabs/Cube");
}
  1. 프리팹 뿐만 아니라 다양한 에셋들을 불러오기 가능
void Start()
{
	GameObject cube = Resources.Load<GameObject>("Prefabs/Cube");
    TextAsset text = Resources.Load<TextAsset>("Text/texttile_01");
    Texture2D texture = Resources.Load<Texture2D>("Textures/texture_01");
    Sprite sprite = Resources.Load<Sprite>("Sprites/sprite_01");
    AudioClip audioClip = Resources.Load<AudioClip>("Audio/audioClip_01");
}

0개의 댓글