- Home /
C# Displaying List Elements in Multiples
Hi everyone, I'm trying to display list elements in multiples. I want it to display it in multiples of five and I want it to display like the following below but with just one line of Debug.Log. I've tried using for loops and messing with their proportions. But that didn't work and I'm not sure what I'm doing wrong.
Debug.Log(someList[5]);
Debug.Log(someList[10]);
Debug.Log(someList[15]);
Debug.Log(someList[20]);
Answer by markedagain · Aug 26, 2013 at 09:46 PM
for (int i = 5; i <= 20; i = i + 5) {
Debug.Log(someList[i]);
}
How do you get that to work with a GUI.Button? I would like for it to go through the multiples as I click the button. I tried the following below but it goes through the entire list when I click on the GUI.Button once.
if (GUI.Button(new Rect(10, 10, 50, 50), "SomeButton")){
for (int i = 5; i <= 20; i = i + 5) {
Debug.Log(someList[i]);
}
}
you should setup a global variable and in your button click simply keep adding currentNum = currentNum + 5
Like this:
private int _count = 0;
if (GUI.Button(new Rect(10, 10, 50, 50), "SomeButton")){
Debug.Log(someList[_count]);
_count += 5;
}
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
C# Randomly Adding Elements from stringListA to stringListB 1 Answer
C# Adding Multiple Elements to a List on One Line 5 Answers
C# Dividing Gameobject List by Half 1 Answer
C# Displaying a List in Series 2 Answers