Prefab을 별도의 드래그 없이, Script에서 불러올 때 쓰는 방법.
아래와 같이 지정하면, 이미 해당 경로에 저장된 prefab을 불러올 수 있다.
Assets/Resources/buildEffect01.prefab
여기서 중요한 것은, Assets/Resources 폴더 안에 prefab을 넣어놔야 한다는 점.
GameObject를 가져오는 것이기 때문에 (GameObject)를 이용해서 불러오면 된다.
public GameObject buildEffect;
void Start()
{
buildEffect = (GameObject)Resources.Load("buildEffect01");
}
자세한 내용은 아래 링크를 참고했음.
Unity - Scripting API: Resources.Load (unity3d.com)
Unity - Scripting API: Resources.Load
This method returns the asset at path if it can be found, otherwise it returns null. Note that the path is case insensitive and must not contain a file extension. All asset names and paths in Unity use forward slashes, so using backslashes in the path will
docs.unity3d.com
'유니티' 카테고리의 다른 글
UI Panel, Prefab으로 지정하여 모든 Scene에서 로딩 (0) | 2023.03.27 |
---|---|
[유니티] DateTime.Utc로 시간 기록/시분초 구현하기 (0) | 2023.03.16 |
[C#] 한 글자 씩 나타나게 하는 방법. Substring 이용. (0) | 2023.03.12 |
[유니티] DOTween이용해서 Panel 깜빡이기 (0) | 2023.03.09 |
[유니티] EASY SAVE와 GPGS를 이용하여 클라우드 저장하기 (0) | 2023.03.05 |