Skip to main content
add tag for describe; slight correction to make question sound less like a resource request
Source Link
Gnemlock
  • 5.3k
  • 5
  • 28
  • 59

I'm trying to get a 2d tilemap rendering but somethings not clicking with me about the 2d coordinates...

Here's my basic tilemap class -

public class Map : MonoBehaviour {
public Transform tilePrefab;

public int mapWidth;
public int mapHeight;
public Transform[,] map;

// Use this for initialization
void Start () {
    map = new Transform[mapWidth, mapHeight];

    for (int y = 0; y < mapHeight; y++)
    {
        for (int x = 0; x < mapWidth; x++)
        {
            Transform tile = Instantiate(tilePrefab, new Vector3 (x, y, 0), Quaternion.identity) as Transform;
            tile.parent = transform;
            map[x, y] = tile;
        }
    }
}

But this is rendering the tilemap from the origin - enter image description here

I want that tilemap to be dynamically centered on the camera like - enter image description here

What I can't seem to work out is how to dynamically work out the coordinates to move that tilemap so that it's centered in the camera after it has been created.?

Any additional help /, or pointers to some decent resources would be much appreciated, cheers.

I'm trying to get a 2d tilemap rendering but somethings not clicking with me about the 2d coordinates...

Here's my basic tilemap class -

public class Map : MonoBehaviour {
public Transform tilePrefab;

public int mapWidth;
public int mapHeight;
public Transform[,] map;

// Use this for initialization
void Start () {
    map = new Transform[mapWidth, mapHeight];

    for (int y = 0; y < mapHeight; y++)
    {
        for (int x = 0; x < mapWidth; x++)
        {
            Transform tile = Instantiate(tilePrefab, new Vector3 (x, y, 0), Quaternion.identity) as Transform;
            tile.parent = transform;
            map[x, y] = tile;
        }
    }
}

But this is rendering the tilemap from the origin - enter image description here

I want that tilemap to be dynamically centered on the camera like - enter image description here

What I can't seem to work out is how to dynamically work out the coordinates to move that tilemap so that it's centered in the camera after it has been created.

Any help / pointers to some decent resources would be much appreciated, cheers.

I'm trying to get a 2d tilemap rendering but somethings not clicking with me about the 2d coordinates...

Here's my basic tilemap class -

public class Map : MonoBehaviour {
public Transform tilePrefab;

public int mapWidth;
public int mapHeight;
public Transform[,] map;

// Use this for initialization
void Start () {
    map = new Transform[mapWidth, mapHeight];

    for (int y = 0; y < mapHeight; y++)
    {
        for (int x = 0; x < mapWidth; x++)
        {
            Transform tile = Instantiate(tilePrefab, new Vector3 (x, y, 0), Quaternion.identity) as Transform;
            tile.parent = transform;
            map[x, y] = tile;
        }
    }
}

But this is rendering the tilemap from the origin - enter image description here

I want that tilemap to be dynamically centered on the camera like - enter image description here

What I can't seem to work out is how to dynamically work out the coordinates to move that tilemap so that it's centered in the camera after it has been created?

Any additional help, or pointers to some decent resources would be much appreciated, cheers.

Source Link
Marklar
  • 135
  • 1
  • 6

Unity 2d coordinates

I'm trying to get a 2d tilemap rendering but somethings not clicking with me about the 2d coordinates...

Here's my basic tilemap class -

public class Map : MonoBehaviour {
public Transform tilePrefab;

public int mapWidth;
public int mapHeight;
public Transform[,] map;

// Use this for initialization
void Start () {
    map = new Transform[mapWidth, mapHeight];

    for (int y = 0; y < mapHeight; y++)
    {
        for (int x = 0; x < mapWidth; x++)
        {
            Transform tile = Instantiate(tilePrefab, new Vector3 (x, y, 0), Quaternion.identity) as Transform;
            tile.parent = transform;
            map[x, y] = tile;
        }
    }
}

But this is rendering the tilemap from the origin - enter image description here

I want that tilemap to be dynamically centered on the camera like - enter image description here

What I can't seem to work out is how to dynamically work out the coordinates to move that tilemap so that it's centered in the camera after it has been created.

Any help / pointers to some decent resources would be much appreciated, cheers.