2D Toolkit Forum
2D Toolkit => Support => Topic started by: regnared on November 08, 2012, 08:16:10 pm
-
How would you code-wise get the information of particular tiles? Say I want to use that string field to add different information to the tile.
When there is a collision with a tile I want to check its property.
Solid, non-solid, ice, breakeable, slow, hurtful , poison, etc. (Things that would not make sense to prefab, etc.)
(https://dl.dropbox.com/u/16537765/string_info_tile.jpg)
Or maybe it could be cool to have the possibility to add properties fields to tiles. A bit like Unity does with tags.
-
int tileId = tileMap.GetTileIdAtPosition(pos, layer);
if (tileId >= 0)
{
tk2dRuntime.TileMap.TileInfo tileInfo = tileMap.GetTileInfoForTileId(tileId)
string str = tileInfo.stringVal;
}
That should do it
-
I've searched in the documentation but didn't find a solution. How do you go about acquiring the tileMap information to work in your code?
Something like : tileMap = GameObject.Find("Map Render Data"); ??
Or do you use prefabs?
I know how to move tk2dsprites around the scene, find gameobjects and play with their basic unity information, but actually acquiring the object and its tk2d information I'm not sure how.
Thanks for the help so far. :)
-
You should do it as you would referencing any other object in Unity.
In your script, add a variable
public tk2dTileMap tileMap;
and from the inspector, drag the tilemap object onto it to link it to the reference.
-
Sorry about my noobies questions, I didn't know you could use tk2d variables directly with the unity inspector. (Used to only use Unity variables for that).
Everything is working really nicely now! A big thank you for helping me out. This knowledge helped me out way more then you can imagine. :) Rarely have I experienced awesome support by passionate people. :)
Thanks for making a really sweet tool. ;D
-
Glad its sorted, and really glad you like 2D Toolkit :)