I am trying to take an array of images and display them in buttons. Depending on the size of the array, it is suppose to create a button per image. The problem is that when i try to run the code I get this error:
NullReferenceException: Object reference not set to an instance of an object
Boo.Lang.Runtime.RuntimeServices.InvokeBinaryOperator (System.String operatorName, System.Object lhs, System.Object rhs)
NewBehaviourScript.DrawButtons () (at Assets/NewBehaviourScript.js:13)
NewBehaviourScript.Update () (at Assets/NewBehaviourScript.js:8)
My question is what am I doing wrong?
this is the code:
var numberOfButtonsWide = 6;
var topLeft = Vector2(100,100);
var width = 800;
var buttonHeight = 60;
var myList : Texture[];
function Start(){
DrawButtons();
}
function DrawButtons()
{
var buttonWidth = width/numberOfButtonsWide;
for(var x =0; x < myList.Count; x++)
{
if(GUI.Button(
Rect(topLeft.x + (x % numberOfButtonsWide) * buttonWidth,
topLeft.y + Mathf.FloorToInt(x / numberOfButtonsWide) * buttonHeight,buttonWidth,buttonHeight),
GUIContent (myList[x])))
{
}
}
}