# How to apply wall objects to tiles efficiently

by Dave   Last Updated May 04, 2017 02:13 AM

So i have a tile grid with a tile mask method which calculates the value of each tile like so:

``````        for (int i = 0; i < Tile_List.Count; i++)
{
int value = 0;
Tile tile = Tile_List[i];
if (Tile_Dictionary.ContainsKey(tile.Position_XY + Vector3.left + Vector3.forward))
value += 1;
if (Tile_Dictionary.ContainsKey(tile.Position_XY + Vector3.forward))
value += 2;
if (Tile_Dictionary.ContainsKey(tile.Position_XY + Vector3.forward + Vector3.right))
value += 4;
if (Tile_Dictionary.ContainsKey(tile.Position_XY + Vector3.left))
value += 8;
if (Tile_Dictionary.ContainsKey(tile.Position_XY + Vector3.right))
value += 16;
if (Tile_Dictionary.ContainsKey(tile.Position_XY + Vector3.back + Vector3.right))
value += 32;
if (Tile_Dictionary.ContainsKey(tile.Position_XY + Vector3.back))
value += 64;
if (Tile_Dictionary.ContainsKey(tile.Position_XY + Vector3.back + Vector3.left))
value += 128;

The problem i now have is creating the objects for the tiles is a huge `if/else if` block of code to check for every combination of tile value which just seems pretty inelegant. Given the values range from 0 - 255 theres a lot of numbers that end up needing the same visuals.