- Home /
GUILabel wider than Rect width
My problem can be best shown by this picture: (alt link)
I obviously don't want the text to appear outside of the phone, next to the "from field". (note that the From: is put in the picture itself and the text next to it is the label text)
I have done this before and it perfectly works but for this one it does not work, the code is exact the same and looks like this:
content.image = emailBig;
if (GUI.Button (new Rect ((Screen.width - wBig) / 2, (Screen.height - hBig) / 2, wBig, hBig), content)) {
showBigEmail = false;
Destroy(GameObject.Find("EmailOverlay(Clone)"));
StoryFlowController.walkfile.enabled = true;
}
GUIStyle st = new GUIStyle();
st.fontSize = 16;
st.normal.textColor = Color.gray;
//FROM label
GUI.Label(new Rect(((Screen.width - wBig) / 2) + 110, ((Screen.height - hBig) / 2) + 240, 5, 50), "TTTTTTTTTTTT TTTTTTTTTT TTTTTTTTTTTTTTTTTTTTTTTTTTTTTaaaaTTTTTTTT", st);
I intentionally use as width 5 and height 50 so the text should definitely not appear this long. Does anyone see what the problem is?
Answer by hav_ngs_ru · Dec 08, 2014 at 05:09 PM
Hello, thank you for your answer. I think it is somewhat in the right direction. However after applying
sB.clipping = TextClipping.Clip;
to sB (the GUIStyle) I get the following result: http://imgur.com/ZwoSuvb
The sentence gets cut off while I want it to appear obviously in the 'balloon'.
$$anonymous$$y code looks as follows (for that line)
GUI.Label(new Rect(((Screen.width - wBig) / 2) + 170, ((Screen.height - hBig) / 2) + 160, 60, 150), message, sB);
@gdennis: Well, you have specified a width of 60 pixels and that looks like 60 pixels... (just checked in mspaint, yes exactly 60 pixels ^^)
btw: You have a strange way to calculate your coordinates. Such a system will fail on different solutions. You mix fix pixel-offsets with size dependent elements. You might want to use some Groups to make the positioning simpler
@Bunny83 Thank you for the groups tip, I will definitely look into that.
I do realize that I set the width to 60 pixels, but I also set the height to 150 pixels and I was hoping that would cause the text to enter and continue below it. However I think i missunderstood the use of it; Thank you for the help nontheless
@gdennis: Uhm you didn't set wordwrap to true. I think you're rushing your project a bit too fast. Read the documentation carefully, try to understand the concept and keep your eyes open for useful things ;)
It's also more common to create a GUISkin asset and use that for your styles. That allows you to view all settings in the inspector and you can event change them while in playmode.
Also keep in $$anonymous$$d that the latest version of Unity has a new GUI system which is more WYSIWYG like and has better performance especially on mobile.
Thank you @Bunny83! I may indeed be rushing this a bit, but since it's a school related project, they want to see results every week. I guess if the main functionality is working, at the end turning the coordinates I have now in Groups shouldn't be that much of a hassle I hope.
Your answer
![](https://koobas.hobune.stream/wayback/20220613173442im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Need help with GUI label not displaying variable 1 Answer
full screen wide GUI.Box 3 Answers
Shrink GUI 1 Answer
GUI Label Score Overlapping - Javascript 1 Answer
getting gui error you can only call functions from inside OnGui. 1 Answer