private void PlaceShip(int posX, int posY, int length) { foreach (GameObject ship in Ships) { if (ship.tag == length.ToString()) { if (orientation == Orientation.Vertical) { ship.transform.rotation = Quaternion.Euler(0, 0, 90); } ship.GetComponent <SpriteRenderer>().enabled = false; ship.GetComponent <SpriteRenderer>().sprite = broken[length - 1]; ship.transform.localPosition = new Vector2(posX, posY); ship.transform.localScale = new Vector3(1, -1, 1); ship.tag = "enemyShips"; break; } } for (int i = -1; i <= length; i++) { for (int j = -1; j < 2; j++) { if (orientation == Orientation.Horizontal) { if (posX + i < width && posX + i >= 0 && posY + j < height && posY + j >= 0) { if (i >= 0 && i < length && j == 0) { GC.AIChangeGrid(posY + j, posX + i, 5); } else if (GC.AIReadGrid(posY + j, posX + i) != 1) { GC.AIChangeGrid(posY + j, posX + i, 1); } } } else { if (posX + j < width && posX + j >= 0 && posY + i < height && posY + i >= 0) { if (i >= 0 && i < length && j == 0) { GC.AIChangeGrid(posY + i, posX + j, 5); } else if (GC.AIReadGrid(posY + i, posX + j) != 1) { GC.AIChangeGrid(posY + i, posX + j, 1); } } } } } }