x


how to I reset a health or progress bar

Hi I am stuck and pls need some help. My game is a wordsearch puzzle which has a progress bar. when the bar is filled, the game ends and the player is expected to have completed the game. The problem is that when the player clicks on the replay button the progress bar doesnt reset like a normer Timer would do. Any ideas pls?

more ▼

asked Dec 06 '10 at 11:08 PM

Princess gravatar image

Princess
13 1 1 3

Some code would be helpful. How do you declare your progress bar variable, what do you do to reset the game, etc.?

Dec 06 '10 at 11:10 PM The_r0nin
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Based on your previous information:

if (buttonWasClicked)
{
    progressBar.progess = 0;
}

Based on your update with the link, I am guessing that you want it to be like this:

var barDisplay : float = 0;
var pos : Vector2 = new Vector2(20,40);
var size : Vector2 = new Vector2(60,20);
var progressBarEmpty : Texture2D;
var progressBarFull : Texture2D;

function OnGUI()
{

    // draw the background:
    GUI.BeginGroup (new Rect (pos.x, pos.y, size.x, size.y));

        GUI.Box (Rect (0,0, size.x, size.y),progressBarEmpty);

        // draw the filled-in part:
        GUI.BeginGroup (new Rect (0, 0, size.x * barDisplay, size.y));
            GUI.Box (Rect (0,0, size.x, size.y),progressBarFull);
        GUI.EndGroup ();

    GUI.EndGroup ();

} 

function Update()
{
    barDisplay += Time.deltaTime * 0.05;
    barDisplay = Mathf.Clamp01(barDisplay);
}

function ResetBar()
{
    barDisplay = 0.0f;
}

You can then control the bar by setting enabled = true when you want the bar to tick up, and call ResetBar() when you want it to reset (or just modify barDisplay, it runs between 0 and 1).

more ▼

answered Dec 06 '10 at 11:19 PM

Statement gravatar image

Statement ♦♦
20.1k 35 70 175

Thank you for your response.I got help for the creation of my progress bar from this link:http://answers.unity3d.com/questions/4456. Maybe this could help. I did try something similer to your answer but still didn't get it to work.

Dec 07 '10 at 11:26 AM Princess

thanks alot!!! It worked :-D

Dec 07 '10 at 03:41 PM Princess
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5088
x3695
x350

asked: Dec 06 '10 at 11:08 PM

Seen: 1092 times

Last Updated: Dec 06 '10 at 11:08 PM