0
\$\begingroup\$

I am trying to create a basic tile map script to learn Unity and I am unable to understand why my tiles are spaced far apart and I can't seem to control their spacing.

Moreover, there seems to be a difference between tile map size and Unity sizes, how do I convert tile map size to Unity size?

My understanding of tile maps are limited but here is what I want to do. I want to be able to set tile size, amount of tiles displayed and the spacing between each tiles.

Image: http://puu.sh/in6XW/416f8971bc.png

 public static int TILE_WIDTH = 32;
 public static int TILE_HEIGHT = 32;

 public float tileSize = 0.1f;
 private Transform[,] tiles;

 void Start () {
     var w = 18; // width
     var h = 15;  // height
     tilePrefab.gameObject.GetComponent<SpriteRenderer>();
     tiles = new Transform[w,h];

     for (int y = 0; y < h; y++)
     { 
         for (int x = 0; x < w; x++)
         {
             Transform tile = Instantiate(tilePrefab, new Vector3(x* tileSize,y * tileSize,0),Quaternion.identity)as Transform;
             tile.parent = transform;
             tiles[x,y] = tile;
         }
     }
\$\endgroup\$
0
\$\begingroup\$

Make sure whatever tile prefab you are using is scaled correctly. I recommend using an object which is exactly one unity unit wide

\$\endgroup\$
  • \$\begingroup\$ I don't understand the tile engine's tilesize variable, am I supposed to get it right through trial and error? \$\endgroup\$ – Wraithseeker Jun 13 '15 at 10:47
  • \$\begingroup\$ It looks like its there in order to scale the whole tilemap down \$\endgroup\$ – Daniel Holst Jun 13 '15 at 10:47
  • \$\begingroup\$ Yet you are not scaling the prefab \$\endgroup\$ – Daniel Holst Jun 13 '15 at 10:48
  • \$\begingroup\$ Also line 3 in your start method is redundant \$\endgroup\$ – Daniel Holst Jun 13 '15 at 10:49
0
\$\begingroup\$

I am not sure but it looks like your "pixel to units" value is different, try setting it to your tile size, its very easy to handle it that way and if you do so, set the TILE_WIDTH and TILE_HEIGHT to 1

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.