already answered: http://answers.unity3d.com/questions/1307420/trying-to-get-gameobjects-assigned-to-arrayxy.html#answer-1307502
assigning gameobjects to an 2Darray
really new to Unity and I am trying to recreate a minesweeper kind of game with variable level sizes. i am getting a lot of different pieces from different tutorials and i have figured out how to dynamically create the playing field gameobjects but to do most of the game logic i need to assign these to an array.
and this is where i got stuck. i was successful at first with using the x,y location of the gameobject to assign it in the correct location of the array but now i switch to adaptive screensizes i am not sure anymore how to get the gameobjects into the array.
i had this part when the game objects had a fixed position:
//register to grid
int x = (int)transform.position.x;
int y = (int)transform.position.y;
Grid.elementArray[x, y] = this;
and i am hoping new logic in here when i create the grid. i am looking for any help trying to either find the position of each gameobject. or just a better solution to my problem the i am working towards. it is either really simple and i am not seeing it or i really do not understand arrays.
public void GenerateGrid()
{
GameObject cellInputField;
RectTransform rowParent;
for (int rowIndex = 0; rowIndex < numOfRows; rowIndex++)
{
rowParent = (RectTransform)Instantiate(panelRow);
rowParent.transform.SetParent(Gridset);
rowParent.transform.localScale = Vector3.one;
for (int colIndex = 0; colIndex < numOfColumns; colIndex++)
{
cellInputField = (GameObject)Instantiate(cellgrid);
cellInputField.transform.SetParent(rowParent);
cellInputField.GetComponent<RectTransform>().localScale = Vector3.one;
countTotCell += 1;
}
}