private void RemoveElement(int idx) { if (idx < 0 || idx >= mActiveElements.Count) { return; } Transform outTrans = mActiveElements[idx]; mInactiveElements.Add(outTrans); mActiveElements.RemoveAt(idx); LevelSection section = outTrans.GetComponent <LevelSection>(); if (section != null) { section.OnDeactivated(); } outTrans.gameObject.SetActive(false); }
private void GetNextElement(float startX) { if (mInactiveElements.Count <= 0 || !mIsSpawning) { return; } // Fetch relevant sections int prevSectionLevel = 1; if (mActiveElements.Count > 0) { LevelSection prevSection = mActiveElements[mActiveElements.Count - 1].GetComponent <LevelSection>(); if (prevSection != null) { prevSectionLevel = prevSection.pEndingPlatformLevel; } } List <Transform> mSearchElements = new List <Transform>(); for (int i = 0; i < mInactiveElements.Count; ++i) { LevelSection sect = mInactiveElements[i].GetComponent <LevelSection>(); if (sect == null || sect.pStartingPlatformLevel == prevSectionLevel) { mSearchElements.Add(mInactiveElements[i]); } } int rnd = Random.Range(0, mSearchElements.Count); Transform outTrans = mSearchElements[rnd]; mActiveElements.Add(outTrans); //mInactiveElements.RemoveAt(rnd); mInactiveElements.Remove(outTrans); outTrans.gameObject.SetActive(true); LevelSection section = outTrans.GetComponent <LevelSection>(); if (section != null) { section.OnActivated(mLanes, mSpanX); } outTrans.position = new Vector3(startX, outTrans.position.y, outTrans.position.z); }