Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Good Way to Store Tile Data?

Discussion in 'Scripting' started by Afropenguinn, Jan 17, 2015.

  1. Afropenguinn

    Afropenguinn

    Joined:
    May 15, 2013
    Posts:
    305
    Think back to games like Advance Wars, when in the level editor you could see it had a list of tiles that could be applied to any location on the map. What would be a good way to go about setting these tiles up in code to be applied to a tile based map like that? I have thought of storing just an enum in each tile that says "Plain", "Mountain", ect. and just using that to reference its data. Since buildings will have stats that change throughout the game each tile will already have to store some variables so I had also thought about giving each tile two classes (depending if a building is on it or not). Any suggestions as to how you would go about this? And code wise, what would you store this list of tiles that need to be referenced as?
     
    Last edited: Jan 17, 2015
  2. TheForsaken95

    TheForsaken95

    Joined:
    Aug 29, 2014
    Posts:
    30
    This might not to apply to a situation as advanced as a strategy game, but anything that is related to a grid I like to store in a 2D array. You could also skip the process of adding variables to the tile, for stats like health, armor, ect. And add a second grid layer to store objects over the first grid layer that stores terrain data, that way you would be able to generate the map separately from the buildings.