public GridPoint closestGridPoint(Vector2 plainPoint) { GridPoint res = new GridPoint(Mathf.RoundToInt(plainPoint.x - psqrt3 * plainPoint.y), Mathf.RoundToInt(plainPoint.y * 2.0f * psqrt3)); foreach (GridPoint nei in res.AdjacentPoints()) { if ((PlainPoint(nei) - plainPoint).sqrMagnitude < (PlainPoint(res) - plainPoint).sqrMagnitude) { res = nei; } } return(res); }
void electrify() { GridPoint nearestGridPoint = hexHandler.closestGridPoint(new Vector2(gameObject.transform.position.x, gameObject.transform.position.z)); List <Wire> hitWires = new List <Wire>(); HexagonBase nexHexBase = hexHandler.getHexagon(nearestGridPoint); if (nexHexBase is HexagonPower) //ha vmi megrázza, akkor a egközelebbi hatszög biztosan hatótávon belül van { foreach (Wire w in ((HexagonPower)nexHexBase).wires) { if (w != null) { if (w.powered) { hitWires.Add(w); } } } } foreach (GridPoint gPoint in nearestGridPoint.AdjacentPoints()) { HexagonBase hexBase = hexHandler.getHexagon(gPoint); if (hexBase is HexagonPower) { HexagonPower hex = (HexagonPower)hexBase; if (inLethalRange(hexBase)) { foreach (Wire w in hex.wires) { if (w != null) { if (w.powered) { hitWires.Add(w); } } } } } } int killerWireIndex = Random.Range(0, hitWires.Count); hitWires [killerWireIndex].Kill(); gameObject.GetComponent <ZombieScript> ().Die(); }