Assigning GUITexture through Javascript

Hello,

I’ve been trying to get a bit of code working. below is a truncated version for demonstration purposes. I’m trying to figure out how to store an array of GUITextures, that I can then access values to. I’ve banged my head against this all day, and I have not found a very good example online of how this is achieved. Here is what I am trying to do.

I have been able to create the array, but not populate it. Since, I have not achieved that I also do not know if the color assignment, position and scale variables have been set. I think those should work, but then a again, I must be missing something fundamental. Is GUITextures just not intended to be scripted? I find that hard to believe. If anyone has any ideas I would love to hear them.

Best Regards,

Stephen

var numberOfButtons:int = 7;

var buttonBGArray = new GUITexture[numberOfButtons];

for(var x:int = 0; x < numberOfButtons; x++)
{
var bgColor:Color;
	bgColor = Color(1,0,0,.5);
	
	buttonBGArray[x].texture = textureArray[categoryTextureNumber];
	buttonBGArray[x].color = bgColor;
	buttonBGArray[x].transform.position = Vector2(xPlacement,yPlacement);
	buttonBGArray[x].transform.localScale = Vector2(buttonWidth,buttonHeight);
}

What is textureArray? What is categoryTextureNumber?

–

1 Answer

1

The array buttonBGArray only holds the references, not the GUITextures themselves. I suspect that for each element you must create an empty GameObject and add to it a GUITexture with AddComponent:

for(var x:int = 0; x < numberOfButtons; x++)
{
    var gObj = new GameObject("GO"+x);  // create the game object
    gObj.AddComponent("GUITexture");    // add the GUITexture...
    buttonBGArray[x] = gObj.guiTexture; // and save its reference
    buttonBGArray[x].texture = ...
    ...