I have a level generating script that generates levels based on the colour values of an image’s pixels, however it won’t actually instantiate my prefabs! What is wrong with it?
public Texture2D map;
public colorToPrefab [] colorMappings;
void Start ()
{
generateLevel ();
}
void generateLevel ()
{
for(int x = 0; x < map.width; x++)
{
for(int y = 0; y < map.height; y++)
{
generateTile(x, y);
}
}
}
void generateTile (int x, int y)
{
Color pixelColor = map.GetPixel (x, y);
if (pixelColor.a == 0)
{
return;
}
foreach (colorToPrefab colorMapping in colorMappings)
{
Vector2 position = new Vector2 (x, y);
if(colorMapping.color.Equals(pixelColor))
{
Instantiate(colorMapping.prefab, position, Quaternion.identity, transform);
}
}
}
