animating a GUI based on pickups

In my game I have a temperature gauge, it goes up based on time.

The idea is that to keep it down you have to pick things up. I can get it to animate going up fine, it doesn’t seem to pay attention to what I try for making it go down.

In my playerCollision I have this when the player collides with the pickup objects:

ScoreKeeper.temperatureAdjust = 5 ;

In my ScoreKeeper script I am doing this;

static var temperatureAdjust : int = 0 ;

function Update ()
{
TemperatureUpdate();
}

function TemperatureUpdate ()
{

var temperature : int = (Time.time - temperatureAdjust) ;

if ((temperature >= 111 ) (temperature <= 120))
{
guiTexture.texture = temperature12tex;
guiTexture.enabled = true ;
}
else if ((temperature >= 101 ) (temperature <= 110))
{
guiTexture.texture = temperature11tex;
}

This continues down in increments of 10, displaying smaller images that represent the temperature.

The problem is that this doesn’t seem to work that I can see.

Second, is that it’s not the most elegant solution I think to use different png files for the length of the thermometer. It would be better to scale the gui, but I havent’ done anything like that yet, and don’t know how feasible it is.

I’d settle for getting my logic to work for the above.

I also confess that I’m out of practice scripting and don’t know the proper way to get feedback in a debug so that it reports the current value of my “temperature”.

Any feedback on these issues would be appreciated.

cheers

You may achieve scaling by modifying width and height of a GUITexture.

What are exactly temperatureXtex ? Small subdivisions of a thermometer ?

Yes exactly. I haven’t seen anything on scaling gui textures yet anywhere, which would be ideal and more accurate.

So I divided up my texture and depending on the size use a different one.

I got some direction to this question from answers.unity3d.com so I thought I’d share the solution and where I’m at. One of the things I was doing wrong when I set this up is that I didn’t identify my variable as a float, so it wasn’t updating at first.

static var temperature : float = 0 ;
static var temperatureAdjust : float  = 0 ; 

function LateUpdate ()
{
	
	TemperatureUpdate();
}

function TemperatureUpdate () 
{

    var temperature = .01 ;
    
	
	guiTexture.texture = temperature12tex;   // texture to scale up
	guiTexture.pixelInset.height += temperature;   // adjust height during game up
	guiTexture.pixelInset.height -= temperatureAdjust;  //subtract from height 
	guiTexture.enabled = true ;

	var temperatureAdjust = 0;  // reset the adjuster back to zero

}

This is in my playerCollision script this info is in the collider, so when the player picks certain things up the temperature goes down.

ScoreKeeper.temperatureAdjust = .02 ;
yield WaitForSeconds(.25);
ScoreKeeper.temperatureAdjust = 0 ;[/code]