|
I have a prefab that get instantiated many times when my scene loads. The prefab has a MonoBehavior script attached that initialized a list of C# delegates and also a list of co-routines. Functions/methods will be chosen at random, and called on the prefab instances. These lists need to be initialized only once, and they will be identical for each instance of the prefab. Whats the best way to initialize the lists once and have each instance of the prefab refer to the lists?
(comments are locked)
|

Will a static member variable of the prefab class work for you?
public class PrefabClass : MonoBehaviour { public static MyStaticClass staticStuff; public void Awake(){ if(staticStuff == null){ staticStuff = new MyStaticClass(); } } }
That seems to be a good option. Thanks!