There is a 2d grid for example 7(column)x16(row). A total of 111 cells are obtained with an index from 0 to 111. Along the perimeter of this grid are 7 numbers and 16 letters. I want to refer to the index of each individual cell not by their number, but for example using the text field to send commands 1a, 2b, 3c, etc.
I introduced it so that the string element of the array - "numbers[0]" and "letters[0]" will be equal to the original cell of the grid with the number 0. Then it turns out to associate the elements of the arrays with the grid index it will be necessary to add +1 to the string element "letters[0] -> letters[1]" in the case when the value of the grid row does not change, but the column changes (for example, 1a -> 1b). And in this case, add +16 to the value of the previous row of the grid (1a -> 2a). I tried to create two one-dimensional arrays "numbers[]" and "letters[]" with a cycle for, but I had a problem, and how to actually associate the data of this array with the cell index if I know the number of columns and rows of the grid.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GridsNL : MonoBehaviour {
public int indexCellStart;
private int countRow;
private int countColumn;
// Use this for initialization
void Start () {
Grid grid = Grid.instance;
countRow = grid.rowCount;
countColumn = grid.columnCount;
CreateArray();
}
// Update is called once per frame
void Update () {
}
public void CreateArray()
{
int[] numbers = new int[countRow];
for (int countRow = 0; countRow < numbers.Length; countRow++)
{
//Debug.Log(countRow);
}
string[] letters = new string[countColumn]
for (int countColumn = 0; countColumn < letters.Length;
countColumn++)
{
//Debug.Log(countColumn);
}
}
I understand that maybe I need to use some kind of cyclic construction inside an array.