Hey all,
I’ve just made a quick, rough cutt stat system in Unity. Problem is, it looks so messy! I was wondering if anyone could provide some input on how I could clean up this code? I mean, the code works as it should, but I want to learn about better ways to do things so I can use it for future reference
The code…
// Unlock that cursor
Cursor.lockState = CursorLockMode.None;
// Begin that group
GUI.BeginGroup(new Rect(Screen.width / 2 - 175, Screen.height / 2 - 175, 350, 350), "");
// Draw them labels and boxes
GUI.Box(new Rect(0, 0, 350, 350), "Stats: ");
GUI.Label(new Rect(10, 20, 200, 30), "Additonal Points: " + aditionalPoints);
// Strength
GUI.Label(new Rect(10, 60, 100, 30), "STR: " + str);
if(GUI.Button(new Rect(200, 60, 20, 20), " + "))
{
if(aditionalPoints > 0)
{
str = str + 1;
aditionalPoints = aditionalPoints - 1;
}
}
// Intelligence
GUI.Label(new Rect(10, 100, 100, 30), "INT: " + intel);
if(GUI.Button(new Rect(200, 100, 20, 20), " + "))
{
if(aditionalPoints > 0)
{
intel = intel + 1;
aditionalPoints = aditionalPoints - 1;
}
}
// Vitality
GUI.Label(new Rect(10, 140, 100, 30), "VIT: " + vit);
if(GUI.Button(new Rect(200, 140, 20, 20), " + "))
{
if(aditionalPoints > 0)
{
vit = vit + 1;
aditionalPoints = aditionalPoints - 1;
}
}
// Defense
GUI.Label(new Rect(10, 180, 100, 30), "DEF: " + def);
if(GUI.Button(new Rect(200, 180, 20, 20), " + "))
{
if(aditionalPoints > 0)
{
def = def + 1;
aditionalPoints = aditionalPoints - 1;
}
}
GUI.EndGroup();