i have the following class
using UnityEngine;
using System.Collections;
public class Tile_Info
{
int ID;
int Varriation;
}
i would like to access it using
simillar to this
maparray[0,0].tile_id=0
can someone place the code here to help me figure out how to do this please
duck
2
First I'm changing the names slightly to adhere to Unity (and c#) coding conventions. These aren't errors but it's good to stick to:
"Tile_Info" becomes "TileInfo"
“maparray” becomes “map”
“Varriation” becomes “variation”
Now, declare the array like this:
TileInfo[,] map = new TileInfo[width,height];
Next, make sure you populate the array cells with instances of TileInfo, using something like this for each cell which contains a tile:
// fill out the empty array with TileInfo instances:
for (int x=0; x<width; ++x) {
for (int y=0; y<height; ++y) {
map[x, y] = new TileInfo();
}
}
Then you can use the array like this:
TileInfo thisTile = map[x,y];
thisTile.ID = someValue;
thisTile.variation = someValue;
Or directly access the tile's variables:
map[x,y].ID = someValue;
map[x,y].variation = someValue;
And the same for testing:
if (map[x,y].ID == someValue) { ... }
hope this helps!