public static EnemyBase GetObject(EnemyBase.Enemytype Type) { if (instance) { EnemyBase e; if (instance.InActivePool.Any(i => i.etype == Type)) { e = instance.InActivePool.First(i => i.etype == Type); instance.InActivePool.Remove(e); instance.ActivePool.Add(e); e.gameObject.SetActive(true); } else { GameObject g = Instantiate(Resources.Load("Object/Enemies/" + Application.loadedLevelName + "/" + Type.ToString()), Vector3.zero, Quaternion.identity) as GameObject; if(!g) g = Instantiate(Resources.Load("Object/Enemies/" + Type.ToString()), Vector3.zero, Quaternion.identity) as GameObject; g.name = Type.ToString() + " - " + (instance.ActivePool.Count + instance.InActivePool.Count); e = g.GetComponent<EnemyBase>(); instance.ActivePool.Add(e); e.transform.SetParent(instance.transform, false); } e.gameObject.SendMessage("startBehaviours", SendMessageOptions.DontRequireReceiver); return e; } return null; }