GUI power bar - frame rate independence.

I’m creating a power bar that goes up and down for a mobile game. I need the power bar to increase and decrease at the same rate across all platforms for frame rate independence. I’ve been told to use Time.deltaTime, but the screen size seems to effect the rate. Here is some simple code that illustrates my dilemma:

var texture : Texture2D;
var progress : int = 0;
var speed : int = 100;

function Update () 
{
	progress += Time.deltaTime * speed;
	
	if(progress > Screen.width)
	{
		print ("End time is: " + Time.time);
	}
}

function OnGUI()
{
	GUI.DrawTexture(Rect(0,0, progress, 25), texture);
}

In this example, i’m drawing a texture from the left side of the screen to the right side. I want the end time (when the texture crosses the right side of the screen) to be the same no matter what screen size i’m at. Right now, if the screen size is small (about the size of an iPhone), the end time is around 4 seconds. If it’s larger (about the size of an iPad), the end time is about 11 seconds. I’m guessing a possible solution would be to create the speed variable according to the screen size - it seems to work with very minor variances in end times (less than 0.1), but I wanted to see if anyone else had any ideas/thoughts.

Screen.width is in pixels, so naturally that will take longer depending on how many pixels wide the screen is. Also the progress variable should not be an int, it must be a float since Time.deltaTime is a float. One way is to use a GUITexture object instead of OnGUI code, since GUITextures are normalized; you can increase the X scale from 0.0 to 1.0 and it will always look the same on any resolution. (Make sure to set all pixel inset values to 0. Since GUITextures are scaled from the middle, to make a progress bar extend to the right, the X position should always be set to half the X scale.)

–Eric