I’m converting the “Zig-Zag” approach from [here][1] to c# in Unity.
I’ve started the conversion, and it’s nearly working, but there are a couple things I’m not sure how to convert.
Here is my converted version:
public GameObject[] tiles;
void Start () {
int[,] tileMap = new int[,] {
{0, 1, 2, 3},
{3, 2, 1, 0},
{0, 0, 1, 1},
{2, 2, 3, 3}
};
float offset_x;
int tile_width = tiles[0].GetComponent<Sprite>().texture.width;
int tile_height = tiles[0].GetComponent<Sprite>().texture.height;
for (int i = 0; i < tileMap.Length; i++){
if(i % 2 != 0){
offset_x = tile_width / 2;
} else{
offset_x = 0;
}
for (int j = 0; j < tileMap*.Length; j++){*
float x = (j * tile_width) + offset_x;
float y = i * tile_height / 2;
_ Instantiate(tiles[tileMap*[j]], new Vector3(x, y, 0), Quaternion.identity);_
_ }_
_ }_
_ }_
I need some help on the line for (int j = 0; j < tileMap<em>.size; j++){, I’m not sure what the c# equivalent is of tileMap_.size is in Java. I’m assuming that size would be Length, but I’m not sure on how to go about converting the array part tileMap*.
Thanks for any help!
EDIT:
I updated the code, as I realized there where some flaws from not fully understanding the source example
*[1]: 2d - Drawing Isometric game worlds - Stack Overflow