private void Update() { if (parentPopulation) { //take care of the removal of individual when time run out timeLeft -= Time.deltaTime; if (timeLeft <= 0) { parentPopulation.IndividualExhausted(); Destroy(gameObject); } switch (status) { //search of a food node or individual if population is agressive case Status.searching: if (Vector3.Distance(target.position, transform.position) < 0.6f) { target = generatePosition(); aiDestinationSetter.target = target; aIPath.SearchPath(); } break; //if a target is found, go to it case Status.seeking: if (aiDestinationSetter.target && Vector3.Distance(aiDestinationSetter.target.position, transform.position) < 1.2f) { status = Status.eating; } break; //eat the food or individual, increasing the food amount for the population case Status.eating: if (aiDestinationSetter.target) { aIPath.maxSpeed = 0; if (aiDestinationSetter.target.tag == "Food") { parentPopulation.foodEaten(Time.deltaTime / 2 + (stats[(int)GameInfo.PopulationStat.stat.bite] / 10)); } else { parentPopulation.foodEaten(Time.deltaTime * (stats[(int)GameInfo.PopulationStat.stat.agression] / 20)); } } break; } //if the food has decayed, go back to finding a new target if (!aiDestinationSetter.target) { status = Status.searching; target = generatePosition(); aiDestinationSetter.target = target; aIPath.maxSpeed = stats[(int)GameInfo.PopulationStat.stat.speed] * 2f + 15f; aIPath.SearchPath(); } } }