- Home /
Console-like guitext, adding header line gives weird result
Hi, I was using the code from over at: http://answers.unity3d.com/questions/152035/printtogui.html
To add a console-esque debug monitor to my game gui. I was attempting to add a "header-line" that stays at the top of the gui text and tracks certain variables so that we don't have a million messages spamming across the console as something changes. The problem I'm having is that the header line repeats itself everytime we call trackHeader() as if we're adding to it, but we're clearly not.
This is what I've tried, with comments explaining what didn't work:
function trackHeader()
{
myHeader = "";
myHeader = "Camera FoV: " + Camera.main.fieldOfView + " Camera Pos: " + Camera.main.transform.position.ToString();
}
function OnGUI ()
{
trackHeader();
myOutput = ""; //this did nothing
myOutput = myHeader;
myOutput += myLog; //commenting out this line makes the header work fine
myLog = GUI.TextArea (Rect (10, 10, Screen.width-10, Screen.height-10), myOutput);
//myLog = GUI.TextArea (Rect (10, 10, Screen.width-10, Screen.height-10), myOutput + myLog); //This didn't work either
}
I think this has something to do with .js being javascript and I'm missing how something is really a pointer and messing me up.
Edit: This always happens: I find the solution right after I give up and admit I need help. Changing
myLog = GUI.TextArea (Rect (10, 10, Screen.width-10, Screen.height-10), myOutput);
to
myOutput = GUI.TextArea (Rect (10, 10, Screen.width-10, Screen.height-10), myOutput);
seems to have done the trick. Well anyway, enjoy the cool revision of that code!
Your answer
![](https://koobas.hobune.stream/wayback/20220613074319im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Return a string not Working in Unity 2 Answers
Print String 3 Answers
Update the GUI when string changes 2 Answers
Double click on Console Window 1 Answer
Editor Console window message no longer wraps... Help? Please? 1 Answer