public override bool checkProceduralPrecondition(GameObject agent) { // find the nearest tree that we can chop Berrybush[] bushes = (Berrybush[])UnityEngine.GameObject.FindObjectsOfType(typeof(Berrybush)); Berrybush closest = null; float closestDist = 0; foreach (Berrybush bush in bushes) { if (closest == null) { // first one, so choose it for now closest = bush; closestDist = (bush.gameObject.transform.position - agent.transform.position).magnitude; } else { // is this one closer than the last? float dist = (bush.gameObject.transform.position - agent.transform.position).magnitude; if (dist < closestDist) { // we found a closer one, use it closest = bush; closestDist = dist; } } } if (closest == null) { return(false); } targetbush = closest; target = targetbush.gameObject; return(closest != null); }
public override void reset() { collectedFood = false; targetbush = null; startTime = 0; }