示例#1
0
 private void OnTriggerEnter(Collider other)
 {
     switch (antState)
     {
     case AntState.CollectingSugar:
         Sugar sugar = other.gameObject.GetComponent <Sugar>();
         if (seek.target != null && sugar != null)
         {
             if (sugar.gameObject == seek.target.gameObject)
             {
                 sugar.GetEaten();
                 SugarCollected++;
                 if (SugarCollected == SugarToCollect)
                 {
                     antState    = AntState.GoingToColony;
                     seek.target = colonyTransform;
                 }
                 else
                 {
                     sugar = sugarController.GetRandomSugar();
                     if (sugar != null)
                     {
                         seek.target = sugar.transform;
                     }
                     else
                     {
                         antState    = AntState.GoingToColony;
                         seek.target = colonyTransform;
                     }
                 }
             }
         }
         break;
     }
 }
示例#2
0
    void CollectSugar()
    {
        // state update
        if (null != sugar)
        {
            if (Vector3.Distance(sugar.transform.position, transform.position) < 0.5)
            {
                sugar.GetEaten();
                SugarCollected++;

                if (SugarCollected == SugarToCollect)
                {
                    activeState = GoToColony;
                    seek.target = colonyTransform;
                }
                else
                {
                    sugar = sugarController.GetRandomSugar();
                    if (null != sugar)
                    {
                        seek.target = sugar.transform;
                    }
                    else
                    {
                        activeState = GoToColony;
                        seek.target = colonyTransform;
                    }
                }
            }
        }
    }
示例#3
0
    private void OnTriggerEnter(Collider other)
    {
        Sugar sugar = other.gameObject.GetComponent <Sugar>();

        if (seek.target != null && sugar != null)
        {
            if (sugar.gameObject == seek.target.gameObject)
            {
                if (!sugar.IsCollected)
                {
                    sugar.GetEaten();
                    SugarHit = true;
                }
            }
        }
    }