Hello Guest

Author Topic: Switching TileMaps  (Read 3728 times)

mygamingproject

  • Newbie
  • *
  • Posts: 37
    • View Profile
Switching TileMaps
« 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?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Switching TileMaps
« Reply #1 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.

mygamingproject

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Switching TileMaps
« Reply #2 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?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Switching TileMaps
« Reply #3 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);