Hey all,
I’m still learning unity and c# but It seems to me that the only way to create instanced prefabs is to create a public variable and link them into that variable manually. But I want to be able to dynamically switch in code that variable between multiple prefabs. can you literally call a prefab instead of the public variable and manually entering it in?
Thanks
I’m not sure but think you just want to uniquely identify an instantiated object, is that right?
If so then when you instantiate the object store it in a temporary gameObject…
GameOnjet go = Instantiate(someObject, Vector3.zero, Quaternion.identity) as GameObject;
You can then alter a property of the instantiated object, the name for example. Let’s say you have an int called index and each time you instantiate an enemy you add the int to the instantiated objects name then increase the index by one.
go.name = "Enemy_" + index.ToString();
index ++;
Set the int index to equal 1 when you declare it at the top of your script…
private int index = 1;
So the first enemy gets named Enemy_1 and the second Enemy_2 and so on.
Hope that’s what you wanted.