public void Eat() { if (dietType == DietType.Carnivore) { CreatureDebug("EF: " + Sight.EdibleFood.Length + ", CFN: " + (Sight.ClosestFood == null)); } if ((Sight.EdibleFood.Length == 0 || Sight.ClosestFood == null) && (dietType == DietType.Carnivore ? (PreviousFood.Count == 0 || CreatureSight.Closest <GameObject>(this, PreviousFood.Keys.Select(f => f.gameObject).ToArray()) == null) : true)) { if (dietType == DietType.Carnivore) { CreatureDebug("can't find food (" + PreviousFood.Count + ")"); } Roam(4, 8); } else { if (dietType == DietType.Carnivore) { CreatureDebug("finding food"); } activity = CreatureActivity.Eating; if (dietType == DietType.Carnivore && PreviousFood.Count > 0) { if (dietType == DietType.Carnivore) { CreatureDebug("looking for past food (" + PreviousFood.Count + ")"); } FoodSource closestMeat = CreatureSight.Closest <FoodSource>(this, PreviousFood.Keys.Select(f => f.gameObject).ToArray()); navAgent.SetDestination(closestMeat.transform.position); closestMeat.Reserve(); StartCoroutine(EatMeat((MeatFoodSource)closestMeat)); } else { if (dietType == DietType.Carnivore) { CreatureDebug("looking for food"); } navAgent.SetDestination(Sight.ClosestFood.transform.position); Sight.ClosestFood.Reserve(); if (Sight.ClosestFood == null) { return; // in the hypothetical situation that the plant dies before the creature is able to move. } if (Sight.ClosestFood.type == FoodType.Foliage) { StartCoroutine(EatPlant((FoliageFoodSource)Sight.ClosestFood)); } else if (Sight.ClosestFood.type == FoodType.Meat) { StartCoroutine(EatMeat((MeatFoodSource)Sight.ClosestFood)); } } } }
// lifecycle private IEnumerator UpdateSight() { if (SightPosition != transform.position) { Sight = new CreatureSight(this, Physics.OverlapSphere( transform.position, Mathf.Lerp(3, 12, ability[Genotype.Sight]) )); SightPosition = transform.position; } yield return(new WaitForSeconds(Time.deltaTime)); }
void Awake() { timeWaited = timeToWait; vision = GetComponent<CreatureSight>(); lastPosMarker = new GameObject(name+" Last Known Position Marker"); aiPath = GetComponent<AIPath>(); anim = GetComponent<Animator>(); anim.SetBool("Enraged", false); anim.SetBool("Run", false); anim.SetBool("Walk", false); anim.SetBool("Attack", false); anim.SetBool("Search", false); anim.SetBool("Absorb", false); GetNearestWaypoint(); }
// Use this for initialization void Awake () { cs = GetComponent<CreatureSight> (); }