Exemplo n.º 1
0
        public Food GetFoodNear(Vector3 position)
        {
            // find closest food spawner

            float       mostAttractive = float.MinValue;
            FoodSpawner bestFit        = null;

            foreach (var sp in foodSpawners)
            {
                float attr = -(sp.transform.position - position).sqrMagnitude;
                attr += sp.CompleteFoodValue; // spawners with more food are more attractive (to a degree)

                if (attr > mostAttractive)
                {
                    bestFit        = sp;
                    mostAttractive = attr;
                }
            }

            if (bestFit == null)
            {
                return(null);
            }

            mostAttractive = float.MaxValue;
            Food bestFood = null;

            foreach (var f in bestFit.food)
            {
                float attr = Vector3.Distance(f.position, position);
                if (attr < mostAttractive)
                {
                    mostAttractive = attr;
                    bestFood       = f;
                }
            }

            return(bestFood);
        }
Exemplo n.º 2
0
 public void RemoveSpawner(FoodSpawner spawner)
 {
     foodSpawners.Remove(spawner);
 }
Exemplo n.º 3
0
 public void AddSpawner(FoodSpawner spawner)
 {
     foodSpawners.Add(spawner);
 }