2D Toolkit Forum
2D Toolkit => Support => Topic started by: kgilbert2 on February 05, 2015, 04:51:07 am
-
Hi everyone.
I am new to 2D Toolkit. My goal is to make a top down 2D game. To start learning it, I have made a simple script, attached to my camera, to show me the tk2dCamera position using GUILabel, and to get the position for a user's touch on iOS. I am running into trouble when getting a reference to my "Tilemap" object, cast as a tk2dTileMap. I attempted to cast by finding it on GameObject, but it is an invalid cast.
My questions:
What is the correct way to get a tk2dTilemap reference for the Tilemap game object from code?
Would TileMap.GetTileAt() be the correct way to get 0,0 positioned tile if I click in the bottom left corner?
I appreciate any help you are able to offer.
-
If you need a TileMap, in your game object create a field:
public tk2dTileMap myTilemap;
and assign the tilemap in the unity editor.
This will give you the tilemap. Then use the methods of the object to get tiles.
-
You can't cast a game object, you'll need go GetComponent<tk2dTilemap>();
-
I am able to access it through code now and I am continuing to learn.
Thank you both very much.
:)