- Home /
C# how to create a Descending GUI List
how do you create a Descending GUI List? Whenever I try to set up a GUI list I get this blob of text. What am I doing wrong?
using UnityEngine;
using System.Collections;
public class ListofAnimals:MonoBehaviour{
List<string> animals = new List<string>();
Void OnGUI(){
Animals.add("Zebra");
Animals.add("Cheetah");
Animals.add("Elephant");
foreach(string animal in animals)
{
GUI.Label(new Rect(0, 0, 125, 125), animal.ToString());
}
}
}
Answer by Eric5h5 · Jun 20, 2012 at 06:22 AM
You're using the same rect for all the labels; you need to increase the Y component for each one. Also you really don't want to use List.Add in OnGUI, since it will add those items a couple of times per frame, so the list will grow rapidly forever (or rather until it crashes). Plus you don't need to use ToString...they are already strings.
How do you change the rects and increase the Y axis every time a thing is added? I did something similar to this with a for loop but I want to avoid that since I couldn't move it down. Here's its source code
public string[] ExampleText; for(int Et = 0; Et
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
How do you CORRECTLY call methods from another C# file 1 Answer
Issues outputting a list of strings 1 Answer
Method is called, but GUI doesn't show up 1 Answer
creating a list of texture2d components 0 Answers