I want the first GUI button to display the first line, the second GUI button to display the second line, etc.
I also want to be able to tell in the script (c#) witch button was clicked. Any Ideas?
You’ll have you use a stream reader or text reader basically. For the GUI it should be simple to add the buttons…
public class AlterMyName : MonoBehaviour
{
public List<TextObjects> readInFile = new List<TextObjects>();
void Awake()
{
for(int i = 0; i < 10; i++)
{
readInFile.Add(new TextObject("Test" + i, "Test" + i " + Value");
}
}
void OnGUI()
{
Rect buttonRectDescending = new Rect(10, 10, 100, 50);
for(int i = 0; i < readInFile.Count; i++)
{
Rect buttonRectDescending = new Rect(10, 10+(i*55), 100, 50);
if(GUI.Button(buttonRectDescending, readInFile[i].myName))
{
Debug.Log("Caught this Action" + readInFile[i].myName + " Value: " + readInfile[i].myValue)
}
}
}
public class TextObjects
{
public TextObjects(string name, string val)
{
this.myName = name;
this.myValue = val;
}
public string myName;
public string myValue;
}
}
Side note… I don’t recommend using Unity GUI… But its good for beginners.