private void Init() { instance = this; foreach (NPool pool in pools) { pool.Init(); } }
/// <summary> /// Gets next gameObject from the pool /// </summary> /// <param name="name"></param> /// <param name="position"></param> /// <returns></returns> public static GameObject GetNext(string name) { if (instance == null) { instance = FindObjectOfType <NObjectPooler>(); instance.Init(); } NPool pool = instance.GetPool(name); if (pool == null) { Debug.LogError("Pool with name " + name + " doesn't exist"); return(null); } GameObject obj = pool.queue.Dequeue(); obj.SetActive(true); pool.queue.Enqueue(obj); return(obj); }