- Home /
Instanciate gameobject from Resources subfolder
Hi!
I have two prefabs with the same name in the resources folder and I want to instantiate them with the same variable in my script but from two different subfolders in the resources folder so the game can see they are different. How do I do that?
Answer by Dave-Carlile · Nov 02, 2013 at 03:22 PM
Just specify the folder in the resource name when loading...
GameObject go1 = Resources.Load("Folder1/Prefab");
GameObject go2 = Resources.Load("Folder2/Prefab");
The resources folder would look like this:
Resources
Folder1
Prefab
Folder2
Prefab
Yes, i know you can do that but i have a string variable which decides what gameobject should be loades:
I tried: Resources.Load("Folder1/"+myvariable) but no luck there if you understand my question.
Add a call to Debug.Log
and log "Folder1/" + myVariable
and make sure it contains what you expect.
Your answer
Follow this Question
Related Questions
C# Object reference not set to an instance of an object right after GameObject.Instantiate 1 Answer
Instantiated GameObject being deleted when destroying original 1 Answer
Cannot instantiate gameobject 3 Answers
Issues with tracking prefab instances and gameobject naming (JS) 1 Answer
gameObject are not referenced 2 Answers