void SearchNearestRefinery() { if (recheckTimer > 0) { recheckTimer -= Time.deltaTime; return; } var allRefineries = Refinery.allRefineries; allRefineries = allRefineries.FindAll(refinery => refinery.selfUnit.OwnerPlayerId == selfUnit.OwnerPlayerId); float distance = float.MaxValue - 1f; for (int i = 0; i < allRefineries.Count; i++) { float curDistance = (transform.position - allRefineries[i].transform.position).sqrMagnitude; if (curDistance < distance) { nearestRefinery = allRefineries[i]; distance = curDistance; } } recheckTimer = 1f; }
public void SetRefinery(Refinery refinery) { nearestRefinery = refinery; }