Reputation: 11321
private void OnGUI()
{
GUIStyle myStyle = new GUIStyle();
myStyle.fontSize = 20;
GUILayout.BeginVertical(GUI.skin.box);
GUILayout.Label("Replacing");
GUI.Label(new Rect(650, 650, 300, 50), "HELLO WORLD", myStyle);
}
I see the Replacing label but it's font very small. So I wanted to test changing the size using new Rect but I don't see the HELLO WORLD anywhere.
Upvotes: 3
Views: 13056
Reputation: 180
I am using two options: this
GUIStyle headStyle = new GUIStyle();
headStyle.fontSize = 30;
GUI.Label(new Rect(Screen.width / 3, Screen.height / 2, 300, 50), "HELLO WORLD", headStyle);
or this
GUI.skin.label.fontSize = 30;
GUILayout.Label("HELLO WORLD", GUILayout.Width(300), GUILayout.Height(50)))
Upvotes: 5
Reputation: 125245
The Text
is showing but not visible to you because of the values you passed to the Rect
struct. The value of 650 and 650 that is passed to the Rect
struct in the x
,y
argument seem to be bigger than the actual screen size. Reduce it to about 100 and you should be able to see the Text
:
GUI.Label(new Rect(100, 100, 300, 20), "Hello World!", myStyle);
If you want your UI display to be dynamic, I suggest you use Screen.height
and Screen.height
to determine where to place the GUI element and make sure that it works regardless the size of the screen.
For example:
GUI.Label(new Rect(Screen.height / 2, Screen.height / 2, 300, 20), "Hello World!", myStyle);
Finally, I assume this is an Editor code based on your other questions. If it's not then you should be using the new UI system with the Text
component.
Upvotes: 1