public void Tick() { if (unit.resourceTarget == null) { if (Vector3.Distance(unit.transform.position, searchPos) <= 2f) { nearByResources = unit.GetNearbyResources(); if (nearByResources.Count > 0) { nearByResources.Sort(SortByDistance); unit.SetResourceTarget(nearByResources[0]); } } } }