Hi everyone,
I have created a 9x9 grid using black UI Images of sizes 33x3 horizontally and 3x33 horizontally nested in 2 loops i and j (i for rows and j for columns) and an array int [ ] Grid.
I create empty cells in the grid, and try to adapt the grid to the empty cells.
Here’s my code:
void DrawGrid()
{
Vector3 startPosition = transform.position;
float horizontalOffset = Colonnes * cellSize * 0.5f - cellSize * 0.5f;
float verticalOffset = Lignes * cellSize * 0.5f - cellSize * 0.5f;
for (int row = 0; row <= Lignes; row++)
{
for (int col = 0; col <= Colonnes; col++)
{
if ((Grille[row, col] == 0) && (Grille[row, col + 1] == 0))
{
Vector3 position = startPosition + new Vector3(col * cellSize - horizontalOffset, -row * cellSize + verticalOffset);
if (col < Colonnes)
{
CreateLine(verticalLinePrefab, position + new Vector3(cellSize / 2, 0, 0));
}
}
void CreateLine(Image linePrefab, Vector3 position)
{
Image newLine = Instantiate(linePrefab, position, Quaternion.identity);
newLine.transform.SetParent(transform);
}
}
The problem is that this doesn’t create a border.
If you have code like :
for (int row = 0; row <= Lignes; row++)
{
for (int col = 0; col <= Colonnes; col++)
{
if ((Grille[row, col] == 0) && (Grille[row, col + 1] == 0))
{
Vector3 position = startPosition + new Vector3(col * cellSize - horizontalOffset, -row * cellSize + verticalOffset);
if (col < Colonnes)
{
CreateLine(verticalLinePrefab, position + new Vector3(cellSize / 2, 0, 0));
}
}
If you can help me to make the left, right, top, bottom edges taking into account the empty squares.
Your help is welcome,
Thanks,
A+
[ /url]
