//放入一个怪物 public void PutInZombie(ZOMBIE type, GameObject zombie) { if (!zombieList.ContainsKey(type)) { zombieList.Add(type, new List <GameObject>()); } zombieList[type].Add(zombie); //放入游戏物体 }
//实例化怪物 private GameObject InstantiateZombie(ZOMBIE type) { foreach (ZombiePrefab z_p in zombiePrefab) { if (z_p.type == type && z_p.prefab != null) { GameObject go = Instantiate(z_p.prefab, zombiePool); go.GetComponent <Zombie>().myType = type; //新生成怪物时初始化其类型 return(go); } } return(null); }
//取出一个怪物 public GameObject TakeOutZombie(ZOMBIE type) { GameObject zombie = null; if (!zombieList.ContainsKey(type)) { zombie = InstantiateZombie(type); } else { if (zombieList[type].Count <= 0) { zombie = InstantiateZombie(type); } else { zombie = zombieList[type][0]; } } zombie.SetActive(getIsEnable); return(zombie); }