#Trying to figure out how to not hard-code this

1 messages · Page 1 of 1 (latest)

nova anvil
#

`private void GenerateMapData()
{
//Allocate our map tiles
tiles = new int[mapSizeX, mapSizeY];

    int x, y;
    // initialize map tiles
    for ( x = 0; x < mapSizeX; x++)
    {
        for ( y = 0; y < mapSizeY; y++)
        {
            tiles[x, y] = 0;
        }
    }


    //generates large block of tile type 2
    for(x=3; x<= 5; x++)
    {
        for(y=0; y <4; y++)
        {
            tiles[x, y] = 2;
        }
    }
    //generates specific u-shape of tile type 1
    tiles[4, 4] = 1;
    tiles[5, 4] = 1;
    tiles[6, 4] = 1;
    tiles[7, 4] = 1;
    tiles[8, 4] = 1;
    tiles[4, 5] = 1;
    tiles[4, 6] = 1;
    tiles[8, 5] = 1;
    tiles[8, 6] = 1;

    GenerateMapVisual();
}`
#

oops let me explain lol didnt mean to send one sec

#

so i have this code, i followed a tutorial to do a grid based map in unity. In this method, it creates an array of mapsizeX and mapsizeY. that's the size of the map essentially, and where all the tiles are. the first two for loops loop through the method and set every tile to type 0 as default. then, the next for loop is for a specific patter, it creates a large block of tile type 2. then, after that, he had hard set a specific group of tiles to type 1.

#

What im trying to figure out is how i can remove the third for loop and the specific tile setting below and set the tiles in the inspector. that way i can edit maps easier/ have them be different across scenes with the same script.

left spruce
#

You mean not hard coded the u-shape? Store their coordinates then set the tile by iterate through all corrdinates

nova anvil
#

sorry im a somewhat beginner

left spruce
#

I dont know whether list<vector2int> is serialized by engine but you can try it then manually set the coordinates in inspector

#

Then foreach vec2 you have set, map[vec2.x,vec2.y]=1

#

Btw i have to sleep now, you can find others for further help

nova anvil
#

okay, thanks for the help so far

#

ill look into what you said