- Home /
Stat bars in Menu system?
I'm making a racing game. In the menu, the player has the ability to choose which car they would like to use. Each car has 3 main stats, Top Speed, Acceleration, and Handling. I have a GUI Box with buttons that choose the players car, and set the 3 stats for that car. There is another box beside it that should show the stat bar for those values, but it remains blank. Here is the code for the stat bars:
function statBars()
{
//Handling
GUI.BeginGroup (new Rect (pos.x, pos.y, size.x, size.y));
GUI.Box (Rect (100,100, size.x, size.y),progressBarEmpty, "Handling");
// draw the filled-in part:
GUI.BeginGroup (new Rect (0, 0, size.x * handle, size.y));
GUI.Box (Rect (0,0, size.x, size.y),progressBarFull);
GUI.EndGroup ();
GUI.EndGroup ();
//Speed
GUI.BeginGroup (new Rect (pos.x, pos.y - 20, size.x, size.y));
GUI.Box (Rect (0,0, size.x, size.y),progressBarEmpty, "Top Speed");
// draw the filled-in part:
GUI.BeginGroup (new Rect (0, 0, size.x * speed, size.y));
GUI.Box (Rect (0,0, size.x, size.y),progressBarFull);
GUI.EndGroup ();
GUI.EndGroup ();
//Accelleration
GUI.BeginGroup (new Rect (pos.x, pos.y - 40, size.x, size.y));
GUI.Box (Rect (0,0, size.x, size.y),progressBarEmpty, "Acceleration");
// draw the filled-in part:
GUI.BeginGroup (new Rect (0, 0, size.x * accl, size.y));
GUI.Box (Rect (0,0, size.x, size.y),progressBarFull);
GUI.EndGroup ();
GUI.EndGroup ();
}
Handle, Speed and accl are the variables set when the player chooses a car.
This is the code called when a player chooses a car:
if (GUI.Button (Rect (Screen.width/3 -105, Screen.height/2+30,160,20), "1971 Dodge Charger")) {
car = "Dodge Charger";
speed = 85;
accl = 90;
handle = 50;
statBars();
}
I can't figure out how to make this work. Any help is greatly appreciated!!!
Answer by Berenger · Jun 26, 2012 at 05:05 AM
You have a problem with your groups rects. The handling rect and the speed rect bot use size.y for height, and the speed's y (pos.y - 20) lead me to think that the size is around 20. However, the second group of handling has a rect with 100, 100.
You're making this more complicated than it should be. Simplify it and I bet the problem will stand out.
Your answer
Follow this Question
Related Questions
dropdown menu error 1 Answer
Making a Pause Menu 1 Answer
Menu Button help 1 Answer
How to make a scrollable menu like angry bird? 1 Answer
Dropdown button... 0 Answers