void Start() { sections = new List <SlideSection>(); SlideSection section = Instantiate(slideSectionPrefab, transform).GetComponent <SlideSection>(); section.Init(Vector3.zero, Vector3.forward, maxRadius, sectionLength); sections.Add(section); generatedSections += 1; UpdateSections(); }
void UpdateSections() { for (int i = 0; i < centerProgress + forwardBufferSections - generatedSections; i++) { int sign = Mathf.RoundToInt(Random.value) * 2 - 1; float radius = (Random.Range(0, 1000) / 1000.0f) * (maxRadius - minRadius) + minRadius; SlideSection last = sections[sections.Count - 1]; SlideSection section = Instantiate(slideSectionPrefab, transform).GetComponent <SlideSection>(); section.Init(last.endPoint, last.endDirection, radius * sign, sectionLength); sections.Add(section); generatedSections += 1; } int sectionsToDelete = Mathf.Max(sections.Count - (forwardBufferSections + rearBufferSections), 0); for (int i = 0; i < sectionsToDelete; i++) { Destroy(sections[i].gameObject); } sections.RemoveRange(0, sectionsToDelete); }