0
\$\begingroup\$

I have a script for a vertical progress bar using filled image but the image decreases (basically you can see the full image when the game starts and then it goes down, like a health bar) but since it's a progress bar I need it to increase (at the end I should see the complete image, not at first). This is the code:

public class ProgressBar : MonoBehaviour {

public Image Bar;
public float max_progress = 100f;
public static float cur_progress = 0f;


void Start () {
    cur_progress = max_progress;
}

void Update () {
    Bar.fillAmount = cur_progress / max_progress;
}

And I have ProgressBar.cur_progress -= 0.4f; in the bullet script because it should increase everytime you kill an enemy. I tried writing += instead of -= but it doesn't work (the image is filled and it doesn't increase or decrease), and i think that is not incorrect so I don't know what the problem is. Thanks in advance.

\$\endgroup\$
2
\$\begingroup\$

Delete the line

cur_progress = max_progress;

from your Start() method. This is the part that currently says "Start 100% full."

Other than that, your idea to change the ProgressBar.cur_progress modification to += is correct.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.