private void checkNeighbors(GameObject center) { GameObject link = null; //the Peg object to link with Peg linkScript = null; //the Peg stript attached to the Peg object Peg centerScript = center.GetComponent <Peg>(); int x = (int)center.transform.position.x / 3; //x coordinate of first peg int z = (int)center.transform.position.z / 3; //z coordinate of first peg int x2; //x coordinate of second peg int z2; //z coordinate of second peg float angle; //angle between pegs //TODO: condense this with some helpers for (int i = 2; i > -3; i--) { for (int j = 2; j > -3; j--) { if (Mathf.Abs(i) + Mathf.Abs(j) == 3) //only check cases of (|2|, |1|) or (|1|, |2|) { if (x + j < 22 && z + i < 22 && x + j >= 0 && z + i >= 0) //only check in bounds (0 to 22) { if (pegs [(z + i), (x + j)]) //if a peg exists at location { link = pegs [(z + i), (x + j)]; linkScript = link.GetComponent <Peg> (); x2 = (int)link.transform.position.x / 3; z2 = (int)link.transform.position.z / 3; angle = Mathf.Atan2(x - x2, z - z2) * 180 / Mathf.PI; if (linkScript.getOwner() == turn) { // if the peg we would link to is owned by the current player, // make the bridge CreateBridge(center.transform.position, (int)angle); } } //peg } //range } //abs } //j } //i }