public IEnumerator Grow() { if (Generation <= 3 && currentGen == Generation) { Vector3 spawnPos = Vector3.zero; Quaternion spawnRot = Quaternion.identity; Transform conPoint = null; spawnPos = parent.Find("ConnectPoint").position; spawnRot = parent.Find("ConnectPoint").rotation; if (lastSegment != null) { conPoint = lastSegment.transform.Find("ConnectPoint"); spawnPos = conPoint.position; spawnRot = conPoint.rotation; } int randPlant = Random.Range(0, plant.PlantSegmentPrefab.Length); if (Generation > 1) { randPlant = 3; } GameObject segmentGo = Instantiate(plant.PlantSegmentPrefab[randPlant], spawnPos, spawnRot, this.transform); if (randPlant != 0 && randPlant != 1) { lastSegment = segmentGo; } GrowthPoint gp = segmentGo.GetComponent <GrowthPoint>(); if (gp) { gp.parent = segmentGo.transform; gp.Generation = Generation++; plant.GrowthPoints.Add(segmentGo); } currentGen = 0; } else { currentGen++; } // somthing is happening after the new growth point is added yield return(null); }
public bool AmIInsideGrowthPoint(GameObject detector) { for (int i = 0; i < m_growths.Count; i++) { GrowthPoint growth = m_growths [i]; Vector3 vec = detector.transform.position - growth.transform.position; if (vec.magnitude < growth.radius) { return(true); } } return(false); }
public void RemoveGrowthPoint(GrowthPoint growth) { m_growths.Remove(growth); }
public void AddGrowthPoint(GrowthPoint growth) { m_growths.Add(growth); }