Creating an array of texture variables

Hello :slight_smile:
I’m trying to animate a GUITexture by switching the textures. I’ve been doing it the long way like so…

var HB001: Texture;
var HB002 : Texture;
var HB003 : Texture;
var HB004 : Texture;

Function Update()
{
var g_Health = gameObject.Find("g_Health");

	if(HEALTH > 97)
	{
		g_Health.guiTexture.texture = HB001;
	}
    else if(HEALTH > 96)
	{
		g_Health.guiTexture.texture = HB002;
	}
    

}

And this works fine, but I know I should be able to loop it. The main problem is generating the many textures (to be applied later in the inspector). I tried these:

var HBarr : Texture[] = new Texture[7];

And

for(var n = 0; n < 87 ; n++)
{
	var HBarr : Texture[5];
}

And others but I can’t get this to work. I still new to programming so I really appreciate the help. I have Sprite Manager 2 but I don’t know if it can be used with GUItextures.

Thanks in advance!

Funny that you mentioned this. I just finished implementing this same behavior in a game that I’m working on ((Un-named iPhone Game) - YouTube). All the explosions there are done like this.

Basically, how I managed to do it was by creating the array (without specifying a size)

var explosionFrames : Texture[];

And then went into the inspector and started manually adding the textures. My Update function then looked like this.

function Update () {
    timer++;
    if ((timer >= playRate) && framePointer < explosionFrames.length - 1) {
	    framePointer++;
	    renderer.material.mainTexture = explosionFrames[framePointer];
	    timer = 0;
    }
}

The timer variable just keeps track of how long it’s been since the last frame was played. The framePointer keeps track of the array index (which frame in the animation we’re at). You’ll probably have to change the renderer.material.mainTexture line to fit your GUITexture needs, but the principle is the same.

-Kith