Hey Guys,
I am creating a script that draws a bunch of random boxes in an editor window, gives them a random colour. This script was seen from the Unite 2011 intro to editor scripting, looked like fun so thought I would give it ago… But its not working… it keeps crashing unity. Could anyone enlighten me as to why?
Here is my script:
using UnityEngine;
using System.Collections;
using UnityEditor;
public class BlockPainter : EditorWindow {
[MenuItem("Level Editor/Block Painter")]
public static void ShowBlockPainterrWindow () {
var window = GetWindow <BlockPainter>();
window.title = "Block Painter";
}
private Color[] pixels;
private int width;
private int height;
public void OnEnable () {
width = height = 8;
pixels = new Color[width * height];
for(int i = 0; i < pixels.Length; i++){
pixels[i] = new Color(Random.value, Random.value, Random.value, 1.0f);
}
}
public void OnGUI () {
var oldColor = GUI.color;
GUILayout.BeginHorizontal();
for(int i = 0; i < width; i++){
GUILayout.BeginVertical();
for(int j = 0; i < height; j++){
GUI.color = pixels[j + i * height];
GUILayout.Box(GUIContent.none, GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(true));
}
GUILayout.EndVertical();
}
GUILayout.EndHorizontal();
GUI.color = oldColor;
}
}
Thanks.