I am trying to push Texture2D into an array whose length is determined by a variable, to then display as GUI labels. I must be doing something wrong as I get a “null” when checking if my texture has been pushed in the array. I’m relatively new to scripting as well. Here is my code:
var numberOfHits = 5;
var emptySlots : Texture2D;
var emptySlotsArray = new Array();
emptySlotsArray.length = numberOfHits;
var buttonQTEWidth = 65;
var buttonQTEHeight = 50;
var buttonQTESpacing = 6;
var screenAdjust : float = 1.3;
function OnGUI () {
for (i = 0 ; i < numberOfHits ; i ++)
{
emptySlotsArray.Push (emptySlots);
GUI.Label(Rect (Screen.width / 2 - (buttonQTEWidth * numberOfHits) / 2 + (i * buttonQTEWidth), Screen.height / screenAdjust - buttonQTEHeight /2 , buttonQTEWidth, buttonQTEHeight), emptySlotsArray*);*
- }*
}
Thanks for your help.
Now that you mention it, there is one more thing: var emptySlots : Texture2D; Do you ever assign that value? You could grab a texture using [
– rutterResources.Load][1], or make it a public variable that you can set from the inspector. [1]:http://unity3d.com/support/documentation/ScriptReference/Resources.Load.html