- Home /
GUI.label overlapping text
Hello,
I am having a problem with my GUI.Label. I am trying to get it to display variables in my code for debugging etc. but when the variable changes it overlaps with the previous and i end up with a mess (see screenshot)
I have looked for solutions online but not found something solid enough to fix this problem. Has anyone ever come across this. Here is my GUI function, as short as it is.
void OnGUI()
{
GUI.Label(new Rect(15, 15, 150, 30), "isJump = " + leftThumbValueX);
}
Is it possible that you maybe have a second label which gets displayed at the same location? I never saw a case where a single label can overlap. There has to be a second label displaying something like: "isJump = " + anotherValue or something like this.
No this is the only instance of this function in my script there is also no other version of this function in any of my other scripts. I can't get my head around it :\
Are there maybe two instances of this script active at the same time. ...maybe attached to different gameobjects?
Hmm, so I removed my movement script from my character and the GUI ran perfectly well....Is there something I am missing when using OnGUI? To test this out i put OnGUI in a separate script and assigned it to my character, it worked well except it ruined the controls....
I have attached the movement function to a main object in the scene that is a parent of a few other bits and pieces....could this be why its overlapping?
Answer by whydoidoit · Apr 28, 2013 at 01:23 PM
If you Subclass a script then clearly those scripts OnGUI will also be called, calling through to the base. Answer - avoid using inheritance in your game logic if you can - it leads to problems like this - try to use a component/composition architecture. If you use inheritance then expect the base class functions to be called.
If you want to hide the underlying scripts OnGUI in a subclass then just do:
void OnGUI() {}
In the subclass.
Your answer
Follow this Question
Related Questions
Unity GUI text displaying as noise 1 Answer
Display GUI Text in update function 1 Answer
GUI text label using variable values and text 1 Answer
GUI labels and buttons overlapping | how can I fix this? 2 Answers
Changing a GUILabel text SIZE 3 Answers