Unity Game Development – 03 – Prefab Brushes and Animated Tiles

What if painting a sprite on to the tilemap was not enough ? What if you had to paint Prefabs ? For example, if you had a collectible that also has animation and needs to be present in several places in your level.

Yes , that’s right . This Prefab Brush is perfect for painting prefabs on to your Tilemap. Now you don’t have to manually drag the prefabs all over the place. You can simply change the default brush and create the prefab

1. Install Prefab brush from Github

Navigate to this url https://github.com/Unity-Technologies/2d-extras and download the zip file containing all the Tilemap related extras.

After unzipping, place the below items into your assets folder

2.Create Prefab to use with the brush

Import a coin sprite, and create a Prefabs folder,and create a new Prefab called coin.

Now when you try to create a game object in your project, you will see the brushes appearing in the Context menu.

Create new Prefab Brush

Next , Lets create a new Prefab brush, and in the Inspector, set the Prefabs Size to 1. It will ask to select a prefab as template, and you can select the coin prefab.

Set prefab in PrefabBrush

3. Selecting new Brush and Paining

In the Tile Panel, at the bottom left side, there is a dropdown to select brushes to paint. You will find the coin brush there. By selecting that , you will be able to paint coins on to the Tilemap

Newly painted prefabs using Prefab Brush

4. Creating Animated Tiles

4. If you notice the content menu, the Animated Tiles are also added when we imported the extras from Github. Let’s create an Animated Tile called CoinShine

In the Sprites folder, i already have 10 Sprites for the Coin Shine Animation. We need to set the number of frames on the Animated Tile , and individually select each frame.

5. Set Sprites in Animated Tile

6. Set speed and import Tile into Tile Palette

After Selecting the sprites, also set the minimum speed to a value higher than 1. I just set it to 30 . You can now drag this CoinShine Tile into the Foreground Palette like any other ordinary sprite.

Using the brush tool and the new Animated Tile in the palette, we can paint it on to the Tilemap.

Painting Animated Tile

Hope you have fun creating animated collectibles from now on. Also, you could place all the collectibles on the Collectibles Tilemap instead of the Foreground Tilemap, that way you will have greater flexibility in using it.