PacMan Level generiert
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f8dfe1c642c42f448fa8273cef04959
|
||||
Reference in New Issue
Block a user