Progress Bar (42253)

Last time you guys were so much help, I thought I would try it again.

I am trying to create a progress bar that will increase along with the player’s score. Once the bar hits the specified amount, the bar will reset and it will activate the multiplier. I understand the “back end” part of what I am trying to do. However, I am having trouble visualizing it for the player.

So my question is: How do I visualize a progress, that will adjust in size with a variable?

2 Answers

2

I usually do progress bar with a group and a texture. The tricky part is to find the %

var percentage : float = 1.0; // Up to you here, something like current / max
GUI.BeginGroup( Rect( 10, 10, 100 * percentage, 10 ) );
    GUI.DrawTexture( Rect( 10, 10, 100, 10 ), tex ); // Note the 100 for the width
GUI.EndGroup();

tex can be a white texture of size (1,1), that way you can change the color with GUI.color. Now, for the multiplier, that concerns the percentage calculation.

I would do something along the lines of

float t = (currentScore-startScore)/(maxScore-startScore); 
float maxWidth = 400; //the total width of your progress bar 
yourGUITexture.pixelInset = new Rect(0, 0, maxWidth * t, 50);

You basically get the percentage of the filled bar and scale your bar by that value.

Sry for all the edits, I'm still trying to get a hang of that markdown stuff :)

Using this answer as spark, I was wondering: Could I use a a normal cube, and then adjust its size using a transform?

A regular cube you mean ? It can be done, but it's a bit harder than GUI stuff. It involves an orthographic camera and a script to transpose screen coordinate to world coordinate.

My mistake, (I am still trying to get used to asking questions where people know no info) but the camera is actually orthographic. However, a follow up would be: which is more resource efficient, GUI or a cube on screen?

Not sure, but I don't think either would have a big impact on performance.