Comparing tiles with tag in a 2D topdown game

I have a procedural generated perlin map and want to instantiate the correct mountains pieces on it.


I know unity has a Rule Tile function but that does not work with procedural generated maps. And i am not smart enough to do a wave function collapse on just the mountain area so i want to compare gameobject tags in 4 directions to figure out what to place.

All tiles have the tags “tile_stone” or “tile_gras” and all are named with their cordinates like “tile_x43_y30”. So how do i write the code? Something like

if("tile on x = 43 and y = y37" has tag "tile_gras")
{
tile_north = "tile_gras"
}

Or if you have another simple suggestion, since i am still a begginner. The mountain will be initiated at level 5, same as the player but the tile map in on level 0 so i cannot use circle colliders and i dont understand raycasts yet. Thank you for reading!

Is this with a tile map or separate game objects? If the former, a tile map is just one game object with only one tag. If the latter, this will not scale at all.

Not sure what you mean by this. You can absolutely use rule tiles with pro-gen stuff. What’s important is to separate the data of your world from the visuals. Namely, you want to be able to represent your world as (nearly entirely) non-Unity data, and then use that to build the visual appearance, probably with a tilemap.

Then you have your own data structure that you can traverse to look for specific things.

These two things:

Are not even REMOTELY compatible. Procgen is HARD, hard, hard, hard.

I seriously recommend you make at least half a dozen or more ultra-simple no-procgen straightforward boring simple games, stuff like flappy birds, pong, space invaders, snake, gather-the-coins, roll-the ball, etc.

Only after you understand your entire environment should you even consider procgen as it is a very abstract concept.

If you insist on procgen, then as Spiney says above, store your own clean data model, ideally completely outside of Unity3D.

If you want an example of storing grid data and then using it to call Unity and visualize, check out my Match3 game:

Tile-based / grid-based 2D games: match3, tetris, chips challenge, rogue, etc:

For any tile-based game such as Match3 or Tetris or a grid-based Roguelike, do all the logical comparisons in your own data storage mechanism for the tiles, such as a 2D array of tiles.

Otherwise you needlessly bind your game logic into Unity objects and the Unity API, making it about 10x more complicated than it needs to be.

If you have no idea how to work with 2D arrays, hurry to some basic C# tutorials for the language portions of it, then look at any good tutorial that uses a 2D array

Here is my Match3 demo using this technique of storing data in a grid. Full source linked in game comments.

It stores all of its data in a 2D array:

PieceController[,] Board;

This allows for easy simple checking in code, not relying on anything like physics.

You should strive to use that pattern for all logic, then only use Unity to present what is happening in the game logic.