Unity3D and GUIStyle

Unity3D 6 ธ.ค. 2014

You can create a GUIStyle by simply declaring a variable at the top of your script which when the script (component) is selected, you can go to the Properties panel and modify the style that way. Unity3d Docs GUIStyle

GUIStyle myStyle;

You can also create a GUISkin and modify the values through the skin as well. Unity3d Docs GUISkin

OR .. you can change the alignment on the individual reference of your label (or button, etc ..) directly through the code below. Be aware though, that once you change the Alignment property, it stays changed for EVERY Other label (or button, etc ..) reference. The way to change just one item would be to follow the code below: (change style, create GUI element, change style back to original state)

GUI.skin.label.alignment = TextAnchor.MiddleLeft;
GUI.Label(Rect(10,10,200,400),"My Text");
GUI.skin.label.alignment = TextAnchor.MiddleCenter;

Below are the possible Text Alignment options. If you want to change the alignment for a button instead of a label, just change the word “label” for whatever default style it is that you want to change.

GUI.skin.label.alignment = TextAnchor.MiddleLeft;
GUI.skin.label.alignment = TextAnchor.MiddleRight;
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
GUI.skin.label.alignment = TextAnchor.LowerCenter
GUI.skin.label.alignment = TextAnchor.LowerLeft
GUI.skin.label.alignment = TextAnchor.LowerRight
GUI.skin.label.alignment = TextAnchor.UpperCenter
GUI.skin.label.alignment = TextAnchor.UpperLeft
GUI.skin.label.alignment = TextAnchor.UpperRight

 

 

 

 

 

 

แท็ก

Onyx

Just a middle-aged programmer, Can do many things but not the most.