// This a double way communicate method
        public void Communicate()
        {
            print("Communicating");
            if (foragerMemory.foragerCommunicated.GetComponent <ForagerMemory> () != null)
            {
                for (int i = 0; i < foragerMemory.foragerCommunicated.GetComponent <ForagerMemory> ().openlist.Count; i++)
                {
                    foragerMemory.UpdateFoodInfo(foragerMemory.foragerCommunicated.GetComponent <ForagerMemory> ().openlist [i]);
                }
                for (int i = 0; i < foragerMemory.foragerCommunicated.GetComponent <ForagerMemory> ().closelist.Count; i++)
                {
                    foragerMemory.UpdateFoodInfo(foragerMemory.foragerCommunicated.GetComponent <ForagerMemory> ().closelist [i]);
                }

                for (int i = 0; i < foragerMemory.openlist.Count; i++)
                {
                    foragerMemory.foragerCommunicated.GetComponent <ForagerMemory> ().UpdateFoodInfo(foragerMemory.openlist[i]);
                }

                for (int i = 0; i < foragerMemory.closelist.Count; i++)
                {
                    foragerMemory.foragerCommunicated.GetComponent <ForagerMemory> ().UpdateFoodInfo(foragerMemory.closelist[i]);
                }

                foragerMemory.foragerCommunicated.GetComponentInChildren <ForagerCommunicate> ().ExistCommunication();
                ExistCommunication();
            }
        }
Exemplo n.º 2
0
 void OnTriggerEnter(Collider other)
 {
     // If the entering collider is the food...
     if (other.gameObject.CompareTag("Food") && other is SphereCollider)
     {
         // ... the food detected.
         //print("Food in detection field: "+Vector3.Distance(gameObject.transform.position, other.gameObject.transform.position));
         foragerMemory.UpdateFoodInfo(other.gameObject.GetComponent <Food>().info);
     }
 }
        void Collect()
        {
            // Reset the timer.
            timer = 0f;

            // If the food has food to collect...
            if (food != null && foodAmount.currentAmount > 0)
            {
                // ... collect the food.
                collectAmount = Mathf.Min(foodAmount.currentAmount, ForagerCapacity.maxCapacity - foragerCapacity.currentCapacity, collectAmount);
                foodAmount.BeCollected(collectAmount);
                foragerCapacity.AddFood(collectAmount);
            }

            foragerMemory.UpdateFoodInfo(food.GetComponent <Food>().info);
        }