2D Toolkit Forum

2D Toolkit => Support => Topic started by: kgilbert2 on February 05, 2015, 04:51:07 am

Title: How do I get a reference to my tile map?
Post 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.
Title: Re: How do I get a reference to my tile map?
Post by: r0l3k on February 05, 2015, 04:43:18 pm
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.
Title: Re: How do I get a reference to my tile map?
Post by: unikronsoftware on February 05, 2015, 09:19:40 pm
You can't cast a game object, you'll need go GetComponent<tk2dTilemap>();
Title: Re: How do I get a reference to my tile map?
Post by: kgilbert2 on February 06, 2015, 04:43:42 am
I am able to access it through code now and I am continuing to learn.

Thank you both very much.

:)