- Home /
Question by
Schoolfablab · Jun 17, 2020 at 11:56 AM ·
prefabprefab-instancestatestate machineprefab changing at runtime
How can I switch between prefab variants in runtime.
How can I switch between prefab variants in runtime. I don't want to instantiate variants, I just want to have a reference of each variant and change it like a state. I should be an option I could not found it. I will reduce time of creating states significantly or it can be used with a state design pattern. Please if you know a solution to not change every parameter of the gameobject by script let me know.
Comment
Answer by FrameXdropProvrex · Jun 17, 2020 at 05:43 PM
I don't know exactly what you mean, but you could set a gameobject array field where you can drag in your prefabs. Then use the index of a gameobject in the array to select one. Something like this:
public GameObject[] Prefabs;
public int PrefabIndex;
public GameObject GetPrefab()
{
return Prefabs[PrefabIndex];
}