46 lines
1.1 KiB
C#
46 lines
1.1 KiB
C#
using UnityEngine;
|
|
|
|
public class GridLevelFromTex : MonoBehaviour
|
|
{
|
|
public Texture2D tex;
|
|
public int width;
|
|
public int heigt;
|
|
public Color[] pixelFarbe;
|
|
public GameObject blockPrefab;
|
|
void Start()
|
|
{
|
|
width = tex.width;
|
|
heigt = tex.height;
|
|
|
|
pixelFarbe = new Color[width * heigt];
|
|
|
|
for (int i = 0; i < heigt; i++)
|
|
{
|
|
for (int k = 0; k < width; k++)
|
|
{
|
|
//pixelFarbe[k + i * width] = tex.GetPixel(k, i);
|
|
pixelFarbe[k + i * width] = Random.ColorHSV();
|
|
}
|
|
|
|
}
|
|
for (int i = 0; i < heigt; i++)
|
|
{
|
|
for (int k = 0; k < width; k++)
|
|
{
|
|
if(pixelFarbe[k + i * width].grayscale >= Color.gray.grayscale)
|
|
{
|
|
GameObject block = Instantiate(blockPrefab);
|
|
block.transform.position = new Vector3(k, 0, i);
|
|
block.GetComponent<Renderer>().material.color = Random.ColorHSV();
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
}
|