When you still place your tiles
by hand, one after another, then you should definitely watch this!
Auto-Tiling is a cool feature which automatically places your tiles based
on rules you set. And the best thing: It's easy to achieve without any coding required!
I start with a new 2D project. Open the Package Manager und "Window" and go the Unity Registry
tab. Currently the 2D Tilemap Extras Package is still not fully released - if you see it -
fine!- but if click on this little settings icon and "Advanced Project Settings". Here
activate the "Enable Preview Packages".
Now you should see it and can install it.
If you still can't see it, you may use the Unity 2021 beta version where it's not visible
at the time of recording. But you can install it by going to this little plus icon and select "Add
package by name" and just enter its name. It will automatically install by clicking on "Add".
So the package should now be installed.
I added this chocolate Tilemap from a
kenny asset pack because - CHOCOLATE and also a rectangular Tilemap.
In a new folder I called "Tiles", I'll create a so called "Rule-Tile"
under 2D > Tiles > Rule Tile.
In this Inspector dialog we can now easily
create our rules as long as they are not too special. This would require some coding.
As it says on the right, we need to add sprites. I use a center piece as the default one. If you configured everything right,
this won't bother at the end.
I also add this one as the first rule. In
the grid on the right you can specify this rule by clicking on the fields. A green arrow
means that another tile must be adjacent.
A red cross means that
there mustn't be anything.
The little bobble in the center represents
the position of this current tile.
If not open click there at the
bottom to open this preview. This looks a bit odd now, because our ruleset is
not done, but based on what your tileset will be, this is also not reliable to look at.
I highly recommend to test your rules live.
Drag your created rule tile in a palette and draw
something on your Tilemap. As you can see our top tile is already applied when the rules match.
When we now add another rule we can see the changes. So this helps a lot if you are not
quite sure where to put arrows or crosses.
I won't add everything now, but let me
show you some other cool features.
Based on your tiles you may also must
watch out for the diagonal adjacent ones like in this case. By checking
the "Extend Neighbor" checkbox you can even spread your rules out further
which can handle more complex cases.
This diagonal one here is not applied but
rather the center tile. The reason here is it looks almost the same but the one cross.
The center rule is ranked higher in this list so it is applied first. We could just drag it
below or better specify the rule even more.
If you have more than one tile for the
same spot you can change the output to "Random" and increase the size of this list
and now drag your other sprites in. It will now automatically add one of the sprites in the list.
By changing the "Noise" slider you can change the "Random-Factor" which will be used. So now there
are more tiles with candy on top - great.
You can also let the tiles roate randomly or
mirror along the X or Y axis or both of them. In this case the tiles don't change when
mirroring along the x axis, so yeah...
Another cool feature are "Animated
Tiles". You can create them separately but also inside a rule, like this.
How about: you can't jump on those tiles when there is candy because
you want to eat the candy.
Let's switch to another project. This
is how a default RuleTile looks like. With this tile i can create those basic shapes.
But I also have these paths which are three tiles wide. A fully centered one and two small border
pieced. The rules only look good when drawing all three pieces. This is easy by
using this rectangular drawing tool. But the preview of this rule tile look just
strange. That's why I recommend to test your rules right inside your scene.
If you are interested in more let me know in the comments. Thank you for
watching and I'll see you next time.
Thanks, that was very clearly explained.