Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
40 lines (32 sloc) 915 Bytes
using UnityEngine;
using System.Collections;
public class LevelGenerator : MonoBehaviour {
public Texture2D map;
public ColorToPrefab[] colorMappings;
// Use this for initialization
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) {
// transparent
return;
}
foreach (ColorToPrefab colorMapping in colorMappings) {
if (colorMapping.color.Equals(pixelColor)) {
Vector2 position = new Vector2(x, y);
Instantiate(colorMapping.prefab, position, Quaternion.identity, transform);
}
}
}
}