I’m trying to put a variable inside GUITexture for the name of the texture. Something like this. Where Ammo is the current ammo value.
GUITexture.texture = ("%h.psd", Ammo);
Or something like
GUITexture.texture = +Ammo+.psd
Not sure of the syntax on that one.
How many textures do you have? What I’ve always done is to create an array of the textures to load, assign them in the inspector, and then pass in your variable as the index into that array. e.g.
#pragma strict
public var guiTex : GUITexture;
public var texturesToLoad : Texture2D[];
public var Ammo : int = 0;
function Update () {
guiTex.texture = texturesToLoad[Ammo];
}
If you don’t know the syntax, look at the Unity Script Reference for the parameter you’re trying to use.
Don’t know why you’re using a string in defining your texture, are you trying to use a folder? If so, look into Resources.Load. If Ammo is an int, you’d just use Ammo.ToString()… Say each of your textures are named Ammo1, Ammo2, Ammo3 and so on, your texture name would be “Ammo”+Ammo.ToString().
Texture2D tex = (Texture2D)Resources.Load("Textures/Ammo" + Ammo.ToString());
Assuming you have a Resources folder in your Assets folder, a Textures folder inside that Resources folder, and your “Ammo” psd files inside the Textures folder.
If you want to make an array from that folder, have a look at Resources.LoadAll
The syntax would be:
GUITexture.texture = string.Format("{0}.psd", Ammo);