My level editor works by scanning a Texture2D and searching for specific colors. If it finds the color, it instantiates an object. I want to make a folder that you can drop your maps into and the game will take the png and make a map. How can I do that?
Here's my code so far...
It works but the folder feature doesn't.
<
using System.IO;
using UnityEngine;
public class LevelGenarator : MonoBehaviour
{
public Texture2D map;
public string LevelFileName;
public ColorToTile[] colorMappings;
// Start is called before the first frame update
void Start()
{
GenearteLevel();
}
void GenearteLevel()
{
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)
{
// that means that the pixel is transparent so we don't need to make any tiles...
return;
}
foreach (ColorToTile colorMapping in colorMappings)
{
if (colorMapping.color.Equals(pixelColor))
{
Vector2 pos = new Vector2(x, y);
Instantiate(colorMapping.prefab, pos, Quaternion.identity, transform);
}
}
}
}
>