Search Unity

tilemap.SetTiles makes invisible tiles?

Discussion in 'Scripting' started by yashi393, Oct 28, 2018.

  1. yashi393

    yashi393

    Joined:
    Jan 21, 2018
    Posts:
    4
    Asked this in Unity Answers but got nothing, so I'll ask here:

    I'm trying to learn about tilemaps to procedurally generate 100x100 tile levels with dynamically changing tile colors (from collisions, etc.). Past 50x50 using cube gameObjects drops FPS below 30.

    Trying to generate 10x10 to start, this is what I get instead: https://imgur.com/SqRsEJm

    Sample code:

    void Start () {
    Tilemap tilemap = GetComponent<Tilemap>();
    for (int x = 0; x < xSize; x++) {
    for (int z = 0; z < zSize; z++) {
    tilePos = new Vector3Int (x, 0, z);
    if (white) {
    tilemap.SetTile (tilePos, whiteTile);
    drawPoint (tilePos);
    Debug.Log ("white set");
    white = false;
    } else { //black
    tilemap.SetTile (tilePos, blackTile);
    Debug.Log ("black set");
    white = true;
    }
    }
    }
    }
    void drawPoint(Vector3 inPos) {
    Debug.DrawLine(inPos+Vector3.up,inPos+Vector3.down,Color.black,5f);
    Debug.DrawLine(inPos+Vector3.right,inPos+Vector3.left,Color.black,5f);
    Debug.DrawLine(inPos+Vector3.forward,inPos+Vector3.back,Color.black,5f);
    }


    I should be getting alternating rows of white and black tiles but instead just get two rows of black and nothing else. Drawline shows that the tile positions are fine.

    What am I missing?
     
    ebrar likes this.
unityunity