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;
}
}