public void ReturnLaneSectionToPool(GameObject curObject) { List <GameObject> laneList; ObjectDifficulty difficulty = GetDifficultyFromTag(curObject.tag); if (ObjectDictionary.TryGetValue(difficulty, out laneList)) { curObject.SetActive(false); laneList.Add(curObject); } }
private void CreateSectionList(ObjectDifficulty difficulty, List <GameObject> prefabs, int instancesPerPrefab) { List <GameObject> laneList = new List <GameObject>(); foreach (GameObject lanePrefab in prefabs) { for (int i = 0; i < instancesPerPrefab; i++) { GameObject lane = GameObject.Instantiate(lanePrefab) as GameObject; lane.SetActive(false); lane.transform.localPosition = lane.transform.position; laneList.Add(lane); } } ObjectDictionary.Add(difficulty, laneList); }
public GameObject GetLaneSectionFromPool(ObjectDifficulty difficulty) { List <GameObject> laneList; if (ObjectDictionary.TryGetValue(difficulty, out laneList)) { if (laneList != null && laneList.Count > 0) { int randomIndex = Util.Instance.GetRandomValue(0, laneList.Count); GameObject lane = laneList[randomIndex]; laneList.Remove(lane); return(lane); } return(null); } else { Debug.Log("Couldn't get section from pool"); return(null); } }