I'm trying to create a checkerboard alternating tile in Unity, but creating it by hand is time-consuming and cumbersome.
I tried creating a rule tile to achieve the checkered effect, but it hasn't worked since the rule tile doesn't allow checking if the neighbor tile is of a specific type.
How can I achieve a checkerboard effect with automatic tiles to automatically place black and white tiles respectively - alternate between them?
Final script
If you're already familiar with all the steps how to make this work inside Unity, here's the script:
Explanation
To create the desired checkerboard tile rule in Unity, first, create a new C# script and call it something like
AlternatingTile.cs
.Open the script and change the base class to
Tile
.Delete the
Start()
andUpdate()
methods, because we are not usingMonoBehaviour
.Add a class-level
Sprite[]
array for the "black and white" tiles.Create an
override
function forTile.GetFileData
.Now that we created the logic for handling which tiles to draw, let's enable Unity to create the asset for this tile.
Usage
If you followed the same menu item path as in the example above - in Unity Editor, click
Assets > Create > 2D > Tiles > Alternating Tile
Select the asset in your
Project
window, and assign the two tiles you wish to alternate.Drag the asset to your Tile Palette and start painting it. As you can see, the tiles are drawn in alternating pattern (checkered/checkerboard pattern).