NullReferenceException has brought me to my knees once more in the following script:
using UnityEngine;
using System.Collections;
public class ColorPicker : MonoBehaviour {
private Texture2D[] currentColors;
private GameObject[] currentCubes;
Texture2D currentColorTexture;
void Start() {
currentColorTexture= new Texture2D(1,1);
}
void OnGUI() {
for (int aY = 0;aY<currentColors.Length-1;aY++) {
currentColorTexture = currentColors[aY];
GUIStyle currentColorStyle = new GUIStyle();
currentColorStyle.normal.background = currentColorTexture;
if(GUI.Button(new Rect(10,(aY*10) + 10, 10,50), currentColors[aY], ""))
Debug.Log("ah");
}
}
public void UpdateColors() {
currentCubes = GameObject.FindGameObjectsWithTag("Cube");
currentColors = new Texture2D[currentCubes.Length];
for(int aA = 0;aA<currentColors.Length;aA++) {
currentColors[aA] = new Texture2D(1,1);
currentColors[aA].SetPixel((int)0,(int)0, currentCubes[aA].renderer.material.color);
}
for (int aB = 0;aB<currentCubes.Length;aB++) {
for (int aC = 0;aC<currentColors.Length;aC++) {
currentColorTexture.SetPixel(0,0, currentCubes[aB].renderer.material.color);
currentColors[aB] = currentColorTexture;
}
}
}
}
I've literally spent six and half hours trying to find the error in this simple piece of work but it keeps giving me the high-blood-pressure-inducing NullReferenceException.
I would deeply appreciate it if somebody could explain what I'm doing wrong here.
Thanks, Elliot Bonneville