public GameObject GetClosestWater() { WaterDeposit res = null; float closest = Mathf.Infinity; if (playerList.waters.Count > 0) { foreach (WaterDeposit o in playerList.waters) { float dist = (transform.position - o.transform.position).sqrMagnitude; if (res == null || dist < closest) { res = o; closest = dist; } } } if (!res) { return(null); } return(res.gameObject); }
private void GetClosestStore() { HashSet <WaterDeposit> water = owner.playerList.waters; Vector3 pos = resourceStore.transform.position; Vector3 current = ResourceManager.InvalidPosition; foreach (WaterDeposit h in water) { Vector3 distance = h.transform.position - pos; if (distance.sqrMagnitude < current.sqrMagnitude) { resourceDeposit = h; current = distance; } } }
public override void StopActions() { base.StopActions(); resourceDeposit = null; resourceStore = null; }