- Home /
GUIContent Alignment inside a Button
I have a menu with a set of buttons. Inside each button I want to add a texture and a string as GUIContent. Both have to be aligned to the left of the button border. I have tried adding style to the GUIContent (texture and string). But this removes the button border. How can I align the texture and string to the left of the button without making the border to disappear?
var ballTexture : Texture;
var contentStyle : GUIStyle;
function Start ()
{
contentStyle.normal.textColor = Color.blue;
contentStyle.fontSize = 12;
contentStyle.alignment = TextAnchor.UpperLeft;
}
function Update()
{
GUI.skin = MenuSkin;
GUI.BeginGroup(new Rect(Screen.width/2 - 150, heightVariation, 300, 400));
GUI.Box(Rect(0, 0, 300, 400),"");
scrollPosition = GUI.BeginScrollView (Rect(0, 0, 300, 400), scrollPosition, Rect (0, 0, 284, 830));
var contents : GUIContent = new GUIContent("Ball", ballTexture);
if (GUI.Button(Rect(42, 50, 200, 50), contents, contentStyle))
{
//do something
}
GUI.EndScrollView ();
GUI.EndGroup ();
}
Is is possible to add one more line of text in the GUI.Button.? I have tried
var ballButtonContent : GUIContent = new GUIContent(" Ball\n Description", ballTexture);
But "Ball" and "Description" will have the same font styles. I want them to have different font size and color. Please help.
for different font and styles you can draw a button with style1 and label on top of button with style2. using 2 styles in one gui element is impossible. or you can use textures with text that will looks exactly you want to.
Thank you Scroodge$$anonymous$$:) But how to add a label on top of a button?? I want a texture in the left, and two texts-in two lines- next to it. Is it possible to add all these in the button? In my example I have a texture of ball in the left end next to it "Ball" is written. I used GUIContent for adding these two in the button. Now I want a description in the next line of "Ball" with a different style. I don't want to use textures for text as of now.Thanks in advance.
I have experimented with the label. But that's not what I want. I want the description as the button's content. There is no way to do like that?? Adding two lines of text with different styles?
there's no way to do what you want using built-in controls only. in unity one control = one style. you should search for avoiding solutions to achieve this. for example, use pre-generated textures. i mean render text to texture procedurally with styles you want and draw it on button like a simple texture. or simple use another/custom/self-writed controls/GUI.
P.S. don't ask new questions as comment to another questions, especially it already answered 8)
Answer by ScroodgeM · Aug 17, 2012 at 09:30 AM
create GUI skin (project - create - GUI skin)
change button style in it
declare GUISkin variable in GUI script
assign created GUI skin to it
in OnGUI method, use it by 'GUI.skin = yourSkin'
Thank you Scroodge :)...But what styles are to be changed for the left alingnment??
mark answer as correct to close question though. good luck 8)
Your answer
Follow this Question
Related Questions
How do I get the GUI Icon to stretch? 1 Answer
Customize a scripted GUI 1 Answer
GUI toggle help 2 Answers
GUI.DrawTexture with GUIStyle? 1 Answer
copy a GUIStyle into a new GUIStyle var using JavaScript 2 Answers