Hi community. I’m trying to produce a program that generates a gridmap, where each instantiated tile has a script attached generating data unique to each tile. I’m struggling to understand how I can define the name of these instantiated tiles using a coordinate system, shown in the code below. I was attempting to use lists with a row and column value, though it appears lists cannot be used as variable names.
The code (The segment between the two for loops is place where this needs to happen):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GridGeneration : MonoBehaviour
{
public int rows = 10;
public int cols = 10;
public float tileSize = 5f;
void Start()
{
generateGrid();
}
void generateGrid()
{
GameObject referenceTile = (GameObject)Instantiate(Resources.Load("blankTile"));
for (int row = 0; row < rows; row++)
{
for (int col = 0; col < cols; col++)
{
List<int> tileCoordinates = new List<int> { row, col };
GameObject tile = (GameObject)Instantiate(referenceTile, transform);
tile.AddComponent<tileData>();
Debug.Log(tile);
float posX = col * tileSize;
float posY = row * tileSize;
}
}
Destroy(referenceTile);
float gridWidth = cols * tileSize;
float gridHeight = rows * tileSize;
transform.position = new Vector2((gridWidth - tileSize) / -2, (gridHeight - tileSize) / 2);
}
}
Thanks for your time!