- Home /
"Random" Rule Tile
Hello everybody, at the moment I'm making a 2D Platformer with Unity 2017 and work with Tilemaps and Ruletiles.
To my question : I know I can make Rule Tiles but is it possible to set up a Rule Tile and define varieties of lets say the straigth Ground Tile?
To clarify, when I'm drawing a "straight Ground Tile" line with my Rule Tile is it possible to say there are three different "straight Ground Tiles" wich the Rule Tile should randomly pick from so I have a little variety of my Layout to break the monotony of my Level.
I hope you understand my question and could help me with my problem.
Thanks in advance.
Edit : I'm using the 2d-extras asset and want to use the rule tile and the random tile function at the same time.
Check out the 2d-extras for Tile$$anonymous$$aps made by Unity. It includes a Random rule tile, I think that's what you want. I haven't used it, so don't know how it works, but check out this tutorial from Unity, they explain how to use it starting from about 0:50.
I use the 2d-extras but my question is if i can use the rule tile with the function of the rule tile and random tile function.
Sorry, I haven't used tilemaps myself, so I don't know. I just thought you wanted the RandomTile.
Hey did you manage to make it? I really wanted one as well. $$anonymous$$aybe we can make it together on GitHub.
Answer by tormentoarmagedoom · Jun 08, 2018 at 11:12 AM
I see the word "Random" in the title, but there is not in the text.. I understand, you have 3 flat tiles, and want to select only one of them each time in a random way.
Then, you only need to create an array with all 3 tiles. and select one at random
Create an array, called FlatTilesArray
public GameObject[] FlatTilesArray = new GameObject[3];
Assign the tiles in the inspector, and now, you just need to use Random.Range to select one.
SelectedTile = FlatTilesArray[Random.Range(0,FlatTilesArray.Lenght);
Every time will pick one at random from index 0 to index 2
Bye!!
Okay I see what you are saying but I'm not sure if I can change the script from the 2d extras asset that easy. At the moment I can't try it, but as soon as I'm home I will change the script and try if this works.
Thank you for your help.
Edit: I changed the text so there is the word random in my question. ^^
This answer merely describes how to pick randomly from an array in C# and does not answer the OP's question. Why is it marked "Best Answer?"
The question was correctly answered below by btouellette
Answer by btouellette · Feb 13, 2020 at 06:16 AM
On a RuleTile for a specific Sprite you can change Output from Single to Random and it will allow you to define a list of variant tiles that will be randomly chosen between.
Thank you man, this really helped me with my top down game, now I can randomise the grass tiles.
Answer by raiszoliver · Apr 08, 2021 at 04:36 PM
There is an option called Random in the Rule Tile's inspector, in the Output dropdown list. I suppose that's what you meant. Also, there's a brush called Random brush to randomly place (static) tiles.