Example #1
0
    public override bool checkProceduralPrecondition(GameObject agent)
    {
        Stickpile[] stickpiles  = (Stickpile[])UnityEngine.GameObject.FindObjectsOfType(typeof(Stickpile));
        Stickpile   closest     = null;
        float       closestDist = 0;

        foreach (Stickpile sticks in stickpiles)
        {
            if (closest == null)
            {
                // first one, so choose it for now
                closest     = sticks;
                closestDist = (sticks.gameObject.transform.position - agent.transform.position).magnitude;
            }
            else
            {
                // is this one closer than the last?
                float dist = (sticks.gameObject.transform.position - agent.transform.position).magnitude;
                if (dist < closestDist)
                {
                    // we found a closer one, use it
                    closest     = sticks;
                    closestDist = dist;
                }
            }
        }
        if (closest == null)
        {
            return(false);
        }

        targetpile = closest;
        target     = targetpile.gameObject;

        return(closest != null);
    }
Example #2
0
 public override void reset()
 {
     hasPickedUpSticks = false;
     targetpile        = null;
     startTime         = 0;
 }