- Home /
GUI object for every item in array?
Hi, for a Japanese class project, I'm working on an interactive quiz. One part of this quiz involves a series of 160 or so questions, so I was hoping to make an array of all the questions(which could later maybe be placed in a random order). Is there a way to create an individual GUI image and input field for each question using a for loop? The way I currently have it set up, all the fields show, but the user cannot type in the blank for their input because(I think) the for loop is called in OnGUI(), meaning it is constantly refreshed.
script ExecuteInEditMode()
var nameFieldString = "Your Name";
class kanji extends System.Object
{
var kanji : UnityEngine.Texture;
var meaning : String[];
var studentInput : String;
var num : int;
}
var allKanji : kanji[];
function OnGUI () {
nameFieldString = GUI.TextField (Rect (15, 15, 125, 25), nameFieldString);
// iterate through the array
for (var currentKanji in allKanji) {
GUI.Box (Rect (15 +(currentKanji.num * Screen.width/30) + (currentKanji.num * Screen.width/6), 50, Screen.width/6,75), (currentKanji.kanji));
currentKanji.studentInput = GUI.TextField (Rect (15 +(currentKanji.num * Screen.width/30) + (currentKanji.num * Screen.width/6), 130, Screen.width/6, 25), "");
}
}
Answer by whydoidoit · May 21, 2012 at 01:53 AM
You aren't putting the value of currentKanji.studentInput into the TextField (hence anything they type is not seen!)
You need to do the same as your nameFieldString.
currentKanji.studentInput = GUI.TextField (
Rect (15 +(currentKanji.num * Screen.width/30) +
(currentKanji.num * Screen.width/6),
130,
Screen.width/6, 25),
currentKanji.studentInput);
Your answer

Follow this Question
Related Questions
Click on a button that is created post start. 0 Answers
changing GUI Button text with a string array 2 Answers
how to input words from array to GUI? 0 Answers
How to make spaces in between Gui boxes being made in for loops? 1 Answer
How to go around creating inventory with new GUI (4.6 Beta)? 1 Answer