- Home /
Question by
wraithseeker · Jun 13, 2015 at 07:04 PM ·
tilemaptiles
New to tile map creation, question about position of tiles
I am trying to create a basic tile map script to learn Unity and I am unable to understand why my tiles are spaced so apart and I can't seem to control their spacing.
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 class TileMap : MonoBehaviour {
public Transform tilePrefab;
public static int TILE_WIDTH = 32;
public static int TILE_HEIGHT = 32;
public float tileSize = 0.1f;
private Transform[,] tiles;
// Use this for initialization
void Start () {
var w = 18;
var h = 15;
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;
}
}
Comment
Have you tried setting TILE_WIDTH and TILE_HEIGHT to 0.32f, or 3.2f? This seems to be a problem with imported textures' pixels per unit variable.