x


fill bar is working, but status is incorrect

I am making a mini game similar to many facebook games where you click a button a number of times and a bar fills up, where at the end, you get a prize and complete that level of mastery. UPDATE: the progress gets past bronze, but silver goes over 100%. Can someone come to my aid?

    public Texture2D _barTexture;
public Texture2D _barBorder;
public int _fullbar;
public int _adjust;
private int Mastery;
private int mBronze=10;
private string Bronze;
private int mSilver=8;
private string Silver;
private int mGold=5;
private string Gold;
private int mPlatinum=4;
private string Platinum;
private string Level;
private float fillProgress;
private bool showButton;


// Use this for initialization
void Start () {
    Mastery=mBronze;
    showButton=true;

}

// Update is called once per frame
void Update () {

}

void OnGUI(){
GUI.DrawTexture(new Rect(45, Screen.height- 165,314,36), _barBorder);   
if(GUI.Button(new Rect(361, Screen.height-165,85,36),"Do Exercise") && showButton==true){

AdjustBar(Mastery);
    }  
GUI.Label (new Rect (45, Screen.height-130, 300, 50), "Percentage:" +fillProgress);
GUI.Label (new Rect (145, Screen.height-130, 300, 50), "Mastery:" +Level);
GUI.BeginGroup(new Rect(55, Screen.height- 155, _adjust, 15));
GUI.DrawTexture(new Rect(0,0,290,15), _barTexture);     

GUI.EndGroup();     
}

int AdjustBar(int adj){
    CalculateMastery(Mastery);
    _adjust+=adj*3;
    fillProgress+= Mastery;

    if(fillProgress==100){

    Mastery=Mastery-2;
    fillProgress=0;
    _adjust=0;

    }

return _adjust; }

string CalculateMastery(int Mastery){ if (Mastery==10) Level="Bronze"; else if (Mastery==8) Level="Silver"; else if(Mastery==5) Level="Gold"; else if(Mastery==4) Level="Platinum"; return Level; } }

more ▼

asked Jun 13 '12 at 06:44 PM

Gilead7 gravatar image

Gilead7
117 18 33 42

@Gilead, you should probably post your solution as an answer and then accept that answer (using the checkmark). This will mark this question as solved, so nobody else thinks you need help on this issue!

Jun 13 '12 at 08:12 PM You!

Thanks You! The script is progressing, but aid is still needed.

Jun 13 '12 at 08:36 PM Gilead7
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

I thought I would share my joy. It is now working. public Texture2D _barTexture; public Texture2D _barBorder; public int _fullbar; public int _adjust; private int Mastery; private string Level; private float fillProgress; private bool showButton;

// Use this for initialization
void Start () {
    Mastery=10;
    showButton=true;
    Level="Bronze";
}

// Update is called once per frame
void Update () {

}

void OnGUI(){
GUI.DrawTexture(new Rect(45, Screen.height- 165,314,36), _barBorder);   
if(GUI.Button(new Rect(361, Screen.height-165,85,36),"Do Exercise") && showButton==true){

AdjustBar(Mastery);
    }  
GUI.Label (new Rect (45, Screen.height-130, 300, 50), "Percentage:" +fillProgress+"%");
GUI.Label (new Rect (147, Screen.height-130, 300, 50), "Mastery:" +Level);
GUI.BeginGroup(new Rect(55, Screen.height- 155, _adjust, 15));
GUI.DrawTexture(new Rect(0,0,290,15), _barTexture);     

GUI.EndGroup();     
}

int AdjustBar(int adj){

    _adjust+=adj*3;
    fillProgress+= Mastery;
    if(fillProgress>=100){
Mastery=Mastery-2;
       Debug.Log("Mastery Level:"+Mastery);
       if(Mastery==2 && fillProgress>=100){
         showButton=false;
         Debug.Log("All done");
       }
CalculateLevel(Mastery);
    }

return _adjust; }

string CalculateLevel(int Mastery){ if(Mastery==10){ Level="Bronze"; } if(Mastery==8){ Level="Silver"; } if(Mastery==6){ Level="Gold"; } if(Mastery==4){ Level="Platinum"; } fillProgress=0; _adjust=0; return Level; } }

more ▼

answered Jun 14 '12 at 07:49 PM

Gilead7 gravatar image

Gilead7
117 18 33 42

(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:

x4374
x1

asked: Jun 13 '12 at 06:44 PM

Seen: 173 times

Last Updated: Jun 14 '12 at 07:49 PM