Is there a way to attach a script to a tile?


(Tony Trudeau) #1

I tried searching and couldn’t find this.
Using custom properties is there a way on import to unity to have a certain game object have a script attached to it?

As an example:
I have a tile that is a door. Using the objects layer I already import this as a trigger. I want to attach a script to it as well so that when the player touches it something happens.

If I add the script myself in unity then have to reimport my map though this script goes away. So I’d like to have some custom property to tell unity to attach the script I want to this tile as well.

Also, want to say this tool is great and thank you so much for making it!


(Seanba) #2

Also, want to say this tool is great and thank you so much for making it!

You’re welcome :slight_smile:

If you need a tile to have some scripting behavior then you need it to be a game object instead of a vertex quad on a mesh (which is map a tile layer is, a collection of textured quads baked into a mesh).

For that, you want to place those tiles as part of an Object Group in Tiled, as opposed to a tile in a Tile Layer.

I talk about that a bit in this blog post here. Look at the part about “Appearing Blocks” which is kind of similar to a door that is open/closed: http://www.seanba.com/megadadadventures.html

Hope that helps.


(Tony Trudeau) #3

Hey that did it! Just needed to be an object and not a tile. I can now set the spawn points of monsters in tiled, which is awesome.