public override void Update(MonoBehaviour origin) { WillGrow = WillGrow || (Random.value <= _spawnOddsPerDay); if (WillGrow) { Vector3Int dir = Vector3Int.zero; TestPlant originPlant = (origin as TestPlant); Plant plant = originPlant.GetComponent <Plant>(); Plant hit = plant.VegetationSys.GetOccupationNear(_leaf.Position, ref dir); if (hit) { if (hit.GetComponent <TestPlant>() != null) { originPlant.DeregisterLeaf(_leaf, false); Object.Destroy(_model); return; } hit.OnAttemptDestroy(dir); } if (!plant.VegetationSys.AttemptOccupy(origin.transform.position, plant)) { originPlant.DeregisterLeaf(_leaf, false); Object.Destroy(_model); } return; } if (--_survivalDaysLeft == 0) { (origin as TestPlant).DeregisterLeaf(_leaf, false); Object.Destroy(_model); } }
public override void Update(MonoBehaviour origin) { if (Random.Range(0f, 1f) <= _chanceToSpawn) { Vector3 targetPos = _leaf.Position; float randomAngle = Random.Range(0f, Mathf.PI * 2f); targetPos += new Vector3(Mathf.Cos(randomAngle) * _distanceSpawned, 0f, Mathf.Sin(randomAngle) * _distanceSpawned); TestPlant plant = origin as TestPlant; plant.AddTestPlantToSystem(targetPos, _leaf.Position); if (--_amountSpawned == 0) { plant.DeregisterLeaf(_leaf, true); } } }