- Home /
GUILayout Icon + Text
Hello Everybody
I Have a GUILayout.label("WhatEver"); i just need add Icon To This Label
i followed this Link
But the Problem That its need 2 Label Is there way to make it in 1 Label? and Thanks
Answer by GuyTidhar · Feb 26, 2013 at 01:36 PM
You can either define a GUIStyle from within the code
(http://docs.unity3d.com/Documentation/ScriptReference/GUIStyle.html)
Or define the 'Label' guistyle in a new GUISkin
http://docs.unity3d.com/Documentation/Components/class-GUISkin.html
This way you could define a background image for the label, and offset the text if needed.
You Didnt Get It -.- I Need GUILayout.Label Contain a TEXT And ICON
I did.
If you'd set the GUILayout.Label with the GUIStyle which is defined with an image as background for 'normal' status, you will get that image - your icon.
If you don't want the icon to be directly behind the text, you can , from within the GUIStyle, offset the text.
You could also, just set the 'Label' item in a GUISkin you create in your project the same way, then set
GUI.skin = yourSkinReference;
Right before calling:
GUILayout.Label("WhatEver");
This will draw the label with the style you have defined in the inspector.
Again, take a look at this:
http://docs.unity3d.com/Documentation/Components/class-GUISkin.html
Answer by ptyalisme · Jun 25, 2014 at 07:40 PM
I got the same problem, here my solution, hope it help other people.
http://docs.unity3d.com/Manual/gui-Basics.html
public Texture2D icon;
void OnGUI () {
GUI.Box (new Rect (10,10,100,50), new GUIContent("This is text", icon));
}
Answer by Prosto_Lyubo · Nov 12, 2017 at 07:41 PM
This generates single label that looks at the player. Image is on the left of the text.
private void OnDrawGizmos(){
GUIContent gUIContent = new GUIContent( "text",
EditorGUIUtility.FindTexture( "Animation.Record" ) );
Handles.Label( this.transform.position, gUIContent );
}
Your answer
Follow this Question
Related Questions
Fade out GUILayout Area? 1 Answer
Why does old text in GUILayout not disappear? 1 Answer
For Loop GUILayout.Label Problems 1 Answer
GUI labels and buttons overlapping | how can I fix this? 2 Answers
GUILayout Sort Problem 1 Answer