Hello,
I am trying to load dynamic values into guitext I am getting some strange behaviour
the debug works… but the data does not get displayed…
please have a look at the code below , i added comments on the behavior
any advice will great
thank you
private var Malaf2 : TextAsset;
//drang into place in the inspector
var ans1:GUIText;
var question:GUIText;
// array to hold the questions files
var myQuestions : Object[];
function Start(){
//loading the xml files from directory
myQuestions = Resources.LoadAll("questions",TextAsset);
//get a random file with its question and answers
Malaf2= myQuestions[Random.Range(0, myQuestions.Length)];
// load the values by calling function
LoadStuff();
}
function LoadStuff(){
//Malaf2= myQuestions[Random.Range(0, myQuestions.Length)];
//do we have a file if yes keep going
if(Malaf2 != null)
{
// read the xml file(the random one from above(start)
var reader:XmlTextReader = new XmlTextReader(new StringReader(Malaf2.text));
while(reader.Read())
{
// read question
if(reader.Name == "Question")
{
//assign question value to the gui
question.text= reader.GetAttribute("Text")+ " ";//no data getts into the gui
Debug.Log(question.text); //debug works fine
}
// read answer1
if(reader.Name == "Answer1")
{
ans1.text = reader.GetAttribute("Text"); // returns empty
ans1.text = reader.GetAttribute("Text").toString;
//if I was toString error (MissingMethodException: Method not found: 'System.String.toString'.)
//but some data shows up
Debug.Log(ans1.text); //works fine
}
} //end reader
} // end checking for null file
}// end function