2D Toolkit Forum

2D Toolkit => Support => Topic started by: mygamingproject on September 02, 2014, 08:57:18 pm

Title: Switching TileMaps
Post by: mygamingproject on September 02, 2014, 08:57:18 pm
I have a gamescene which has a tilemap,  all working nicely for 3 levels.

However, I have added a new level within the same gamescene but the tilemap is slightly different. I don't want to duplicate the gamescene for the sake of about 30% of the tiles so is there a way of hiding a tilemap and showing another?  There is no renderer attached to a tilemap so that isnt a default option which made my think because of this it wasnt the right route to take.

What would you suggest?
Title: Re: Switching TileMaps
Post by: unikronsoftware on September 03, 2014, 12:18:55 pm
The tilemap renderers are attached to the tilemap render data object. You can show or hide those. That will probably be the easiest way in your situation.
Title: Re: Switching TileMaps
Post by: mygamingproject on September 03, 2014, 09:07:38 pm
Thanks for the tip but how do you reference the renderer and dataobject as have tried tagging

http://imgur.com/YFWSjzB

and then referencing like this:

Code: [Select]

GameObject tileObj = GameObject.FindGameObjectWithTag("StandardTileMap");
tk2dTileMap tilemap = tileObj.GetComponent<tk2dTileMap>();
tilemap.renderData.renderer.enabled = false;

But get the error:

Quote
MissingComponentException: There is no 'Renderer' attached to the "TileMap Render Data" game object, but a script is trying to access it.
You probably need to add a Renderer to the game object "TileMap Render Data". Or your script needs to check if the component is attached before using it.
GameLoop.Awake () (at Assets/Scripts/GameLoop.cs:36)


Have I misunderstood what you mean?
Title: Re: Switching TileMaps
Post by: unikronsoftware on September 04, 2014, 09:37:52 am
Yes, Just enable / disable the gameobject. The tilemap render data is split up into multiple renderers which are children of the root object.

Code: [Select]
tilemap.SetActive(false);