So i have TileMap Script to create the whole map with the cube that have class on TileType, for the first time the map is generated, and then i want to make a highlight on the cube, by replacing the tiles(cube) with the different one using the highlight() .
TileMap Script
void Start()
{
//Allocate the tiles of the map
tiles = new int[mapSizeX, mapSizeZ];
//Create the map
CreateMap();
//Generate the map
GenerateMap();
}
void GenerateTiles(int x, int z)
{
TileType tt = tileTypes[tiles[x, z]];
if (tt != null)
Instantiate(tt.tileVisualPrefab, new Vector3(x, -0.1f, z), Quaternion.identity);
else
{
Debug.LogWarning("tt is empty");
Debug.Log("On Coordinate " + x + "," + z);
}
}
void GenerateMap()
{
for (int x = 0; x < mapSizeX; x++)
{
for (int z = 0; z < mapSizeZ; z++)
{
GenerateTiles(x, z);
}
}
}
void CreateMap()
{
//Create the map based on the tiles
for (int x = 0; x < mapSizeX; x++)
{
for (int z = 0; z < mapSizeZ; z++)
{
tiles[x, z] = 0;
}
}
//Create the road
tiles[4, 2] = 1;
tiles[4, 3] = 1;
tiles[4, 4] = 1;
tiles[5, 4] = 1;
tiles[6, 4] = 1;
tiles[7, 4] = 1;
tiles[3, 4] = 1;
tiles[2, 4] = 1;
tiles[1, 4] = 1;
//Create entry/ exit point
tiles[4, 1] = 3;
//Assign the bool for each type of tiles
for(int t = 0; t<=5;t++)
{
TileType tt = tileTypes[t];
isWalkable[t] = tt.isWalkable;
isDoor[t] = tt.isDoor;
}
}
public void highlight(string status, int x, int z)
{
if (status == "on")
{
temp = tiles[x, z];
tiles[x, z] = 4;
GenerateTiles(x, z);
}
else
{
tiles[x, z] = temp;
GenerateTiles(x, z);
}
}
TileType Class Script
[System.Serializable]
public class TileType
{
public string name;
public GameObject tileVisualPrefab;
public bool isWalkable = false;
public bool isDoor = false;
public bool isHighlight = false;
}o Genert
But when i use the highlight() from the other script i triggered got log “tt is empty”, i’ve checked, the string = on and the x and z value is detected and got to GenerateTiles()
what happen? and how do i make the highlight() to instantiate the tiles??