GUI Texture not changing?

Hi, I am working on a simple HUD for my gun’s ammo clip ammount, however, the GUI text never changes when the ammo decreases. Can anyone tell me why?

function Update () {
	var clip = GunBasis.ammoClip;
	if (clip == 30) {
		guiText.text = "30";
	} else if (clip == 29) {
		guiText.text = "29";
	} else if (clip == 28) {
		guiText.text = "28";
	} else if (clip == 27) {
		guiText.text = "27";
	} else if (clip == 26) {
		guiText.text = "26";
	} else if (clip == 25 ) {
		guiText.text = "25";
	} else if (clip == 24) {
		guiText.text = "24";
	} else if (clip == 23) {
		guiText.text = "23";
	} else if (clip == 22) {
		guiText.text = "22";
	} else if (clip == 21) {
		guiText.text = "21";
	} else if (clip == 20) {
		guiText.text = "20";
	} else if (clip == 19) {
		guiText.text = "19";
	} else if (clip == 18) {
		guiText.text = "18";
	} else if (clip == 17) {
		guiText.text = "17";
	} else if (clip == 16) {
		guiText.text = "16";
	} else if (clip == 15) {
		guiText.text = "15";
	} else if (clip == 14) {
		guiText.text = "14";
	} else if (clip == 13) {
		guiText.text = "13";
	} else if (clip == 12) {
		guiText.text = "12";
	} else if (clip == 11) {
		guiText.text = "11";
	} else if (clip == 10) {
		guiText.text = "10";
	} else if (clip == 9) {
		guiText.text = "9";
	} else if (clip == 8) {
		guiText.text = "8";
	} else if (clip == 7) {
		guiText.text = "7";
	} else if (clip == 6) {
		guiText.text = "6";
	} else if (clip == 5) {
		guiText.text = "5";
	} else if (clip == 4) {
		guiText.text = "4";
	} else if (clip == 3) {
		guiText.text = "3";
	} else if (clip == 2) {
		guiText.text = "2";
	} else if (clip == 1) {
		guiText.text = "1";
	} else if (clip == 0) {
		guiText.text = "0";
	} 
}

Also, is there a simpler way to do all this int to string conversion? lol :smile:

function Update () 
{ 
   var clip = GunBasis.ammoClip; 
   guiText.text = "" + clip;
}

That should be better :stuck_out_tongue:

Ahh, thanks. Like, having 60 worthless lines isnt that bad, untill you make the one showing how much you have, then thats hell. Like way better than having 240 lines (120 rounds) just for that. But I think I will have to do it the way i had if I used textures and not text. And the problem to start was that I didn’t add the script to the guiText, so duh, lol :slight_smile:

No, you’d use an array…there’s never a case where you need to write multiple lines that basically do the same thing. If you ever find yourself writing code like that, then you know you’re doin’ it wrong. :wink:

Also, there’s no reason for that code to be in Update. Unlike OnGUI, once a guiText.text is set, it doesn’t need to be refreshed every frame. So you can just set it when the value actually changes.

–Eric

But what about Texture2D variables? For every texture, you would have to tell it which one to use, right? :smile:

You’d simply use an array of Texture2Ds.

–Eric

I mean like:

var tex1 : Texture2D;
var tex2 : Texture2D;
var tex3 : Texture2D;
//ect, ect....

Right?

No:

var textures : Texture2D[];

By the way, Half-Life is coming to the Mac soon along with the rest of Valve’s games, not to mention Steam.

–Eric

Oh, I see. And yes I know, however, Half-Life might only be Intel, not PowerPC… Multi-Platform is what I want! :smile: