public void SelectArea(Vector2Int index) { if (gridType == GridType.Defense && !setupComplete) { if (currentRotation == ShipRotation.Horizontal) { index.x = Mathf.Clamp(index.x, 1, gridSizeX - 2); if (TileAvailable(index)) { grid[index.x, index.y].GetComponent <TileScript>().SetColor(occupiedColor, true); grid[index.x, index.y].GetComponent <TileScript>().SetHasShip(true); OccupiedCells += "[" + index.x + "," + index.y + "]"; OccupiedNumber++; grid[index.x - 1, index.y].GetComponent <TileScript>().SetColor(occupiedColor, true); grid[index.x - 1, index.y].GetComponent <TileScript>().SetHasShip(true); OccupiedCells += "[" + (index.x - 1) + "," + index.y + "]"; OccupiedNumber++; grid[index.x + 1, index.y].GetComponent <TileScript>().SetColor(occupiedColor, true); grid[index.x + 1, index.y].GetComponent <TileScript>().SetHasShip(true); OccupiedCells += "[" + (index.x + 1) + "," + index.y + "]"; OccupiedNumber++; InstantiateSprite(index); shipCount++; } } else { index.y = Mathf.Clamp(index.y, 1, gridSizeY - 2); if (TileAvailable(index)) { grid[index.x, index.y].GetComponent <TileScript>().SetColor(occupiedColor, true); grid[index.x, index.y].GetComponent <TileScript>().SetHasShip(true); OccupiedCells += "[" + index.x + "," + index.y + "]"; OccupiedNumber++; grid[index.x, index.y + 1].GetComponent <TileScript>().SetColor(occupiedColor, true); grid[index.x, index.y + 1].GetComponent <TileScript>().SetHasShip(true); OccupiedCells += "[" + index.x + "," + (index.y + 1) + "]"; OccupiedNumber++; grid[index.x, index.y - 1].GetComponent <TileScript>().SetColor(occupiedColor, true); grid[index.x, index.y - 1].GetComponent <TileScript>().SetHasShip(true); OccupiedCells += "[" + index.x + "," + (index.y - 1) + "]"; OccupiedNumber++; InstantiateSprite(index); shipCount++; } } if (shipCount >= totalShipCount) { setupComplete = true; } } else if (gridType == GridType.Attack && isActive) { grid[index.x, index.y].GetComponent <TileScript>().SetColor(attackedColor, true); // Tells the server an attack happened gameManager.AttackOpponent(index); } }