- Home /
Question by
vince18800 · May 12, 2020 at 07:54 AM ·
unity 5gameobjectprogrammingprefabs2d array
how to show coordinates on the prefab? Using multidimensional arrays?
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class TileManager : MonoBehaviour { Renderer objRenderer; //to get the bottomleft position for the player public Transform bottomLeftRef; //declaring a gameobject for the tile public GameObject tile;
public GameObject[,] tileArray = new GameObject[9, 9];
private string printValues;
public int i;
public int j;
void Start()
{
gridgenerator();
}
public void gridgenerator()
{
//the outer loop for the grid system = 9by 9 system for the x axis
for (i = 0; i < 9; i++)
{
//the inner loop for the y axis = 9 tiles
for (j = 0; j < 9; j++)
{
//spawning a tile gameobject , seeting position for i on the x-axis and j on the y-axis, setting the rotation to default so the object doesnt rotate at all.
tileArray[i,j] = Instantiate(tile, bottomLeftRef.position + new Vector3(i, j, 0), Quaternion.identity);
}
}
}
public int x;
public int y;
public void setCoord()
{
this.i = x;
this.j = y;
}
} so this is my code and it doesnt print out the coordinates to my gameobject. i want it to be (0,1), (0,2),(0,3) and so on until reaches (8,8)
is there a soultion to this? help
Comment