- Home /
Adding variables together.
I want to make multiple integers that can be changed in the middle of play, and have those integers link up with percentages that update as they do. But I can't wrap my head around getting Unity to understand even basic mathematics.
public int GroupA;
public int GroupB;
public int GroupC;
private int GroupTotal()
{
GroupA + GroupB + GroupC;
}
private float PercentageA()
{
GroupTotal / GroupA;
}
private float PercentageB()
{
GroupTotal / GroupB;
}
private float PercentageC()
{
GroupTotal / GroupC;
}
void Start () {
}
void Update () {
Debug.Log (GroupA, GroupB, GroupC, GroupTotal, PercentageA, PercentageB, PercentageC);
}
Answer by Shameness · Jul 02, 2018 at 07:29 AM
GroupA / GroupTotal ; big number goes bottom, multiply with 100 if you want number between 0 and 100
Answer by Cascadiarch · Jul 02, 2018 at 08:03 AM
That did help, yeah. I also think I also figured out how to make math work in a function. The updated code, between 'public int GroupC' and 'void Start ()' now looks like:
private int GroupTotal;
private float PercentageA;
private float PercentageB;
private float PercentageC;
void PercentileUpdate(){
GroupTotal = GroupA + GroupB + GroupC;
PercentageA = GroupA / GroupTotal;
PercentageB = GroupB / GroupTotal;
PercentageC = GroupC / GroupTotal;
}
Your answer
Follow this Question
Related Questions
how to make particles activate when object moves 3 Answers
Access a variable from another script 1 Answer
How to modify the base movement speed of the character in JS 1 Answer
Can you change Static Variable values from another script? 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers