- Home /
Update function dosent update for GuiText.text
I want to update GuiText.text line by line after reading text file? Unfortunately GuiText.text dosent update even it is in update() function. Is there any issue ? Please help me. My code is as below:
string subtitle;
void AddSubtitle(string text)
{
subtitle = text;
}
void Update ()
{
subtitle.guiText.text = subtitle;
Debug.Log(subtitle.guiText.text);
}
※the value in the debug.log() is changing every fps.
Its not clear to me if the text doesn't update or if it changes every frame, neither how AddSubtitle is called. I'm also wondering if you want to display each single line for X time or have them add up until the whole file is displayed?
It has some restriction to show.For example,there are 3 lines in the file A,B,C I just want to show Line B.I have to check current line is line B or not and should to display on the screen or not.
Answer by fafase · Sep 07, 2012 at 05:47 AM
Is that something like this that you need?:
var str:String[] = new String[3];
str[0]="Line1";
str[1]="Line2";
str[2]="Line3";
var index :int;
var guiOn:boolean;
function Start(){
guiOn=true;
index =0;
guiText.text = str[index];
}
function Update () {
if (Input.GetKeyDown (KeyCode.Space)&&guiOn)
ChangeGUI();
}
function ChangeGUI(){
index++;
if(index>=3){
guiText.enabled=false;
guiOn=!guiOn;
}else guiText.text = str[index];
}
Here is just a simple script that will print the corresponding string and you get to the next one with space. Once you read them all, the GUI is disabled.
Oh and this is directly attached to the GuiText object so you would have to get the component first for your case.
fafase san,Thank you for your answer.But it is still dosent work.I think that is Unity bug.
I known that problem.$$anonymous$$y GuiText is not gameobject.That is prefab. It is work when i use as a GameObject. It dosent work as prefab.After loaded from prefab as a gameobject and instantiate. Do you know any way?
Answer by hirenkacha · Sep 07, 2012 at 06:54 AM
check for the Console Collapse tab. If its selected, same Log will be collapsed.
Yes,I also checked Console.GuiText.text value are updated in console window but not on object in the screen.I was testing with many way.
Your answer

Follow this Question
Related Questions
Update Guitext every frame 1 Answer
GUIText doesn't update 2 Answers
GUIText not updating score.... 1 Answer
Timer lag at GUIText drawing. 1 Answer