Loop variables (Names of Inputfields / Labels)
Hey there! I have 3 Inputfields and 3Labels and i want to get the value from the InputFields into the aCount with a loop, i something like this...
public InputField InFie1, InFie2, InFie3;
public Text Lbl1, Lbl2, Lbl3;
public int aCount, bCount;
for (int i = 1; i < 4; i++)
{
aCount += Convert.ToInt32(("InFie" + i.ToString()).text);
}
But that is not working and i have literaly no clue how to fix that problem :( If you have some advices i would be thankful. And excuse my bad english.
Thanks for reading though!
Answer by andrei2699 · Jul 27, 2016 at 12:39 PM
Try putting the Inputfields in an array and then loop in the array and add the value of the Inputfield.
public InputField[] Fields;
public int aCount;
for(int i=0;i<Fields.Length;i++)
{
aCount += Int.Parse(Fields[i].text);
}
Your answer
Follow this Question
Related Questions
Break the loop when there are no more questions 0 Answers
Unity update does not be called when lock screen 0 Answers
Use of unassigned local variable 'startPos' " & " Use of unassigned local variable 'endPos' 1 Answer
Beginner trying to set up random variable for game + and then some. 2 Answers
[C# NOOB] How can I change a variable in a script from another script? 0 Answers