Example #1
0
    GameObject FindClosestTarget(GoalType mode)
    {
        List <HarvestableController> listToSearch = forest.allHarvestables[mode];

        HarvestableController closest = null;
        float   distance = Mathf.Infinity;
        Vector3 position = transform.position;

        foreach (HarvestableController harvestable in listToSearch)
        {
            Vector3 diff        = harvestable.transform.position - position;
            float   curDistance = diff.sqrMagnitude;
            if (curDistance < distance)
            {
                if (harvestable.harvested == false)
                {
                    closest  = harvestable;
                    distance = curDistance;
                }
            }
        }

        return(closest.gameObject);

        //TODO: Handle the case where no more potential targets remain
    }
Example #2
0
    void Start()
    {
        hc = controller.GetComponent <HarvestableController>();
        pt = controller.GetComponent <ProfsTables>();
        pp = player.GetComponent <PlayerProfs>();

        //Check through the existing harvestables
        for (int i = 0; i < hc.harvestables.Count; i++)
        {
            //Check for a match with this harvestable in the controller
            if (this.gameObject.name == hc.harvestables[i].name)
            {
                maxDensity = hc.harvestables[i].density;
                density    = maxDensity;
            }
        }
    }