I have a itemList, I want to display it in Label and show out when user click buttonM. so I created a variable call dis_M when buttonM clicked dis_M equal to true. Now it is able to display, but one frame can only displays up to 8 items. So, I created a for loop inside a variable l to keep track if l > 7 then I break out the loop. And I have a right left button so when user click left button then the item start from position 8 will be displayed accordingly. Currently what I did was inside display_Menu() method I will check if display_M is true or not, if true, I check if right button is click or left button is click else I called display_M(0); (Start from first item). When I run the game it can display item from 0 to 7, when i click right button the index keep on increasing and then an error message Argument out of range shown. It seems like something is keep looping.I comment all the statement inside display_M() and try print(“Hello”),and it goes into a infinite loop as it keep on printing out the Hello. I am beginner for C# and Unity, I not very sure where goes wrong, and is there any better way to display the item?
List<Item> itemList;
private int index;
void Start (){
index=0;
display = false;
display_B = false;
display_X = true;
display_M = false;
left = false;
right = false;
itemList = GetComponent<dbStartUpInitialization> ().loadItem ();
}
void onGUI(){
if(display){
display_Menu();
}
}
display_Menu(){
GUI.BeginGroup (new Rect (70, 55, 662, 519));{
if(GUI.Button(....ButtonM){
dis_M = true;
}
if(GUI.Button(....ButtonB){
dis_B = true;
}
if(GUI.Button(....ButtonX){
dis_X = true;
}
if(GUI.Button(...RightArrowButton){
}
if(GUI.Button(...LeftArrowButon){
}
if(dis_M){
if(right)
display_M(index+=8);
else if(left)
display_M(index-=8);
else
display_M(0);
}
print(index);
}
GUI.EndGroup ();
}
void display_M(int ind){
GUI.BeginGroup (new Rect (0, 0, 662, 519));{
for (int i = ind; i < itemList.Count; i++) {
if (l < 8) {
GUI.Label (new Rect (x, y, 80, 20), itemList*.ItemName.ToString ());*
GUI.Label (new Rect (x, y + 20, 80, 20), itemList*.Descriptions.ToString ());*
}else{
break;
}
… some variables to keep track x y axis to display the label.
}
}
}