I am trying to get the GUI to display a precentage by calculating it using the variables
basically like this, however, when it shows the % it doesn’t show the correct value ot be displayed. it only shows 0
public class GameScript : MonoBehaviour {
public int ace = 32;
public int ten = 128;
public int nine = 32;
public int eight = 32;
public int seven = 32;
public int six = 32;
public int five = 32;
public int four = 32;
public int three = 32;
public int two = 32;
public int deck;
// Use this for initialization
void Start () {
deck = ace + ten + nine + eight + seven + six + five + four + three + two;
}
// Update is called once per frame
void Update () {
deck = ace + ten + nine + eight + seven + six + five + four + three + two;
}
void OnGUI()
{
if (GUI.Button(new Rect(0, 0, 50, 50), "ace"))
{
ace--;
}
if (GUI.Button(new Rect(50, 0, 50, 50), "ten"))
{
ten--;
}
if (GUI.Button(new Rect(100, 0, 50, 50), "nine"))
{
nine--;
}
if (GUI.Button(new Rect(150, 0, 50, 50), "eight"))
{
eight--;
}
if (GUI.Button(new Rect(200, 0, 50, 50), "seven"))
{
seven--;
}
if (GUI.Button(new Rect(250, 0, 50, 50), "six"))
{
six--;
}
if (GUI.Button(new Rect(300, 0, 50, 50), "five"))
{
five--;
}
if (GUI.Button(new Rect(350, 0, 50, 50), "four"))
{
four--;
}
if (GUI.Button(new Rect(400, 0, 50, 50), "three"))
{
three--;
}
if (GUI.Button(new Rect(450, 0, 50, 50), "two"))
{
two--;
}
GUI.Label(new Rect(0, 50, 50, 50), ace.ToString());
GUI.Label(new Rect(50, 50, 50, 50), ten.ToString());
GUI.Label(new Rect(100, 50, 50, 50), nine.ToString());
GUI.Label(new Rect(150, 50, 50, 50), eight.ToString());
GUI.Label(new Rect(200, 50, 50, 50), seven.ToString());
GUI.Label(new Rect(250, 50, 50, 50), six.ToString());
GUI.Label(new Rect(300, 50, 50, 50), five.ToString());
GUI.Label(new Rect(350, 50, 50, 50), four.ToString());
GUI.Label(new Rect(400, 50, 50, 50), three.ToString());
GUI.Label(new Rect(450, 50, 50, 50), two.ToString());
GUI.Label(new Rect(0, 100, 50, 50), System.Convert.ToString(Calculate(ace)) + "%");
GUI.Label(new Rect(50, 100, 50, 50), System.Convert.ToString(Calculate(ten)) + "%");
GUI.Label(new Rect(100, 100, 50, 50), System.Convert.ToString(Calculate(nine)) + "%");
GUI.Label(new Rect(150, 100, 50, 50), System.Convert.ToString(Calculate(eight)) + "%");
GUI.Label(new Rect(200, 100, 50, 50), System.Convert.ToString(Calculate(seven)) + "%");
GUI.Label(new Rect(250, 100, 50, 50), System.Convert.ToString(Calculate(six)) + "%");
GUI.Label(new Rect(300, 100, 50, 50), System.Convert.ToString(Calculate(five)) + "%");
GUI.Label(new Rect(350, 100, 50, 50), System.Convert.ToString(Calculate(four)) + "%");
GUI.Label(new Rect(400, 100, 50, 50), System.Convert.ToString(Calculate(three)) + "%");
GUI.Label(new Rect(450, 100, 50, 50), System.Convert.ToString(Calculate(two)) + "%");
}
int Calculate(int card)
{
int total= card/deck*100;
return total;
}
}