As you know, Unity has released the Tilemap feature in the 2017.2 Editor release. This is an awesome feature that permits you to create cool maps for your 2D games.
Unfortunately, this feature lacks the Events management capability. That’s why we brought to you this package!
Let’s see how it does work:
Create a tilemap
The first thing to do is, of course, create your awesome map.
For this tutorial
Download and import the package
Go to the Github repository at https://github.com/NTWalkers/unitytilemapevents and download the latest package version found under the Releases folder.
To import the package right-click on the Assets folder under the Project folder and select Import Package -> Custom Package… and then select the downloaded package.
Add your Events Tilemap
The next step is to add yout Events Tilemap to the project.
To do that right click on the Hierarchy and select 2D Object -> Event Tilemap.
An event tilemap it’s still a tilemap so you can draw tiles on it.
Those tiles will represent the actual event.
I suggest putting this tilemap on the higher Sorting Layer. Do not worry, at runtime the events till will automatically hide. This will permit you to see the events on editing.
In my example
Let’s see how the component looks like:
The array of tiles contains all the event tiles drawn.
Following the meaning of tiles parameters :
Name: The name of the event.- Interactable Tag: The tag that the object needs to have to interact with that event.
- Trigger: The type of trigger. Actually supported values are On
Enter Collision and On Interaction. - On Event(): The method or the stack of methods to be called when the event is fired.
Fire the event
Firing the event is pretty simple:
You just need to move your player (or the designated object) into the tile and the event will fire.
Of course your object needs a RigidBody2D and a Collider2D (Box, Circle, Polygon etc etc are all fine).