Quantcast
Channel: Answers for "How to render underlined text in Unity?"
Viewing all 18 articles
Browse latest View live

Answer by samuel.levine

$
0
0
Well, this is a hack, but you can always create a duplicate TextMesh consisting only of underscore characters (e.g. ___________ ).

Answer by ikn

$
0
0
Well in support of the above answer . You can create Rect using same arguments like shown below and can put underscore in String . //Forgot Password button if(GUI.Button(Rect(x, y, width, height)),"Forgot Password",forgetButtonStyle){ Application.OpenURL("http://answers.unity3d.com/questions/topics/underline.html"); } //UnderLine Forgot Password button GUI.Label(Rect(x, y, width, height), "______________", forgetButtonStyle); If you want to reduce the gap between text and underline , you need to reduce height of underline label.

Answer by sschaem

$
0
0
If you need this functionality "TextMesh Pro" support the underlined tag so you can more easily manage underlined text. Normal Underline text ![alt text][1] [1]: /storage/temp/28129-underline.jpg

Answer by OLP

$
0
0
If you are using GUILayout, you can do it by fetching the last item's rectangle: // This displays a button that looks like a label. ExpandWidth(false) ensures // that the underline will have the same size as the text. if (GUILayout.Button("Click me!", EditorStyles.label, GUILayout.ExpandWidth(false))) { Application.OpenURL("http://www.google.com"); } // Get the last rect to display the line lastRect = GUILayoutUtility.GetLastRect(); lastRect.y += lastRect.height - 2; // Vertical alignment of the underline lastRect.height = 2; // Thickness of the line GUI.Box(lastRect, ""); See [GetLastRect][2] [1]: http://docs.unity3d.com/ScriptReference/GUILayoutUtility.GetLastRect.html [2]: http://docs.unity3d.com/ScriptReference/GUILayoutUtility.GetLastRect.html

Answer by ShawnFeatherly

$
0
0
In Unity 4.6. Duplicate the gameobject that has the text component (Ctrl+D). This will retain its positioning information. Then replace every character in the text field with a '_'. You can automate this with the following Underline.cs component to add to any Unity 4.6 gameobject that has a Text component: using UnityEngine; using UnityEngine.UI; [RequireComponent(typeof(Text))] public class Underline : MonoBehaviour { void Start() { var transform = base.transform as RectTransform; // make a stripped down copy of the Text var go = GameObject.Instantiate(transform, transform.position, transform.rotation) as Transform; foreach (var component in go.GetComponents()) { if (component is Text) continue; else GameObject.Destroy(component); } go.SetParent(transform.parent); // make sure transform has original values go.localScale = transform.localScale; var TextComponent = go.GetComponent(); TextComponent.rectTransform.sizeDelta = transform.sizeDelta; // use the copy to create an underline TextComponent.text = new System.Text.RegularExpressions.Regex(".").Replace(TextComponent.text, "_"); } }

Answer by vladipus

$
0
0
Using a combination of OLP's and ikn's answers: if (GUILayout.Button( "Do Stuff", EditorStyles.label, GUILayout.ExpandWidth(false))) { DoStuff(); } var lastRect = GUILayoutUtility.GetLastRect(); GUI.Label(lastRect, "___________"); If this doesn't work for you try increasing and decreasing the number of underscores in the last label.

Answer by samuel-levine

$
0
0
Well, this is a hack, but you can always create a duplicate TextMesh consisting only of underscore characters (e.g. ___________ ).

Answer by ikn

$
0
0
Well in support of the above answer . You can create Rect using same arguments like shown below and can put underscore in String . //Forgot Password button if(GUI.Button(Rect(x, y, width, height)),"Forgot Password",forgetButtonStyle){ Application.OpenURL("http://answers.unity3d.com/questions/topics/underline.html"); } //UnderLine Forgot Password button GUI.Label(Rect(x, y, width, height), "______________", forgetButtonStyle); If you want to reduce the gap between text and underline , you need to reduce height of underline label.

Answer by sschaem

$
0
0
If you need this functionality "TextMesh Pro" support the underlined tag so you can more easily manage underlined text. Normal Underline text ![alt text][1] [1]: /storage/temp/28129-underline.jpg

Answer by OLP

$
0
0
If you are using GUILayout, you can do it by fetching the last item's rectangle: // This displays a button that looks like a label. ExpandWidth(false) ensures // that the underline will have the same size as the text. if (GUILayout.Button("Click me!", EditorStyles.label, GUILayout.ExpandWidth(false))) { Application.OpenURL("http://www.google.com"); } // Get the last rect to display the line lastRect = GUILayoutUtility.GetLastRect(); lastRect.y += lastRect.height - 2; // Vertical alignment of the underline lastRect.height = 2; // Thickness of the line GUI.Box(lastRect, ""); See [GetLastRect][2] [1]: http://docs.unity3d.com/ScriptReference/GUILayoutUtility.GetLastRect.html [2]: http://docs.unity3d.com/ScriptReference/GUILayoutUtility.GetLastRect.html

Answer by ShawnFeatherly

$
0
0
In Unity 4.6. Duplicate the gameobject that has the text component (Ctrl+D). This will retain its positioning information. Then replace every character in the text field with a '_'. You can automate this with the following Underline.cs component to add to any Unity 4.6 gameobject that has a Text component: using UnityEngine; using UnityEngine.UI; [RequireComponent(typeof(Text))] public class Underline : MonoBehaviour { void Start() { var transform = base.transform as RectTransform; // make a stripped down copy of the Text var go = GameObject.Instantiate(transform, transform.position, transform.rotation) as Transform; foreach (var component in go.GetComponents()) { if (component is Text) continue; else GameObject.Destroy(component); } go.SetParent(transform.parent); // make sure transform has original values go.localScale = transform.localScale; var TextComponent = go.GetComponent(); TextComponent.rectTransform.sizeDelta = transform.sizeDelta; // use the copy to create an underline TextComponent.text = new System.Text.RegularExpressions.Regex(".").Replace(TextComponent.text, "_"); } }

Answer by vladipus

$
0
0
Using a combination of OLP's and ikn's answers: if (GUILayout.Button( "Do Stuff", EditorStyles.label, GUILayout.ExpandWidth(false))) { DoStuff(); } var lastRect = GUILayoutUtility.GetLastRect(); GUI.Label(lastRect, "___________"); If this doesn't work for you try increasing and decreasing the number of underscores in the last label.

Answer by samuel-levine

$
0
0
Well, this is a hack, but you can always create a duplicate TextMesh consisting only of underscore characters (e.g. ___________ ).

Answer by ikn

$
0
0
Well in support of the above answer . You can create Rect using same arguments like shown below and can put underscore in String . //Forgot Password button if(GUI.Button(Rect(x, y, width, height)),"Forgot Password",forgetButtonStyle){ Application.OpenURL("http://answers.unity3d.com/questions/topics/underline.html"); } //UnderLine Forgot Password button GUI.Label(Rect(x, y, width, height), "______________", forgetButtonStyle); If you want to reduce the gap between text and underline , you need to reduce height of underline label.

Answer by sschaem

$
0
0
If you need this functionality "TextMesh Pro" support the underlined tag so you can more easily manage underlined text. Normal Underline text ![alt text][1] [1]: /storage/temp/28129-underline.jpg

Answer by OLP

$
0
0
If you are using GUILayout, you can do it by fetching the last item's rectangle: // This displays a button that looks like a label. ExpandWidth(false) ensures // that the underline will have the same size as the text. if (GUILayout.Button("Click me!", EditorStyles.label, GUILayout.ExpandWidth(false))) { Application.OpenURL("http://www.google.com"); } // Get the last rect to display the line lastRect = GUILayoutUtility.GetLastRect(); lastRect.y += lastRect.height - 2; // Vertical alignment of the underline lastRect.height = 2; // Thickness of the line GUI.Box(lastRect, ""); See [GetLastRect][2] [1]: http://docs.unity3d.com/ScriptReference/GUILayoutUtility.GetLastRect.html [2]: http://docs.unity3d.com/ScriptReference/GUILayoutUtility.GetLastRect.html

Answer by ShawnFeatherly

$
0
0
In Unity 4.6. Duplicate the gameobject that has the text component (Ctrl+D). This will retain its positioning information. Then replace every character in the text field with a '_'. You can automate this with the following Underline.cs component to add to any Unity 4.6 gameobject that has a Text component: using UnityEngine; using UnityEngine.UI; [RequireComponent(typeof(Text))] public class Underline : MonoBehaviour { void Start() { var transform = base.transform as RectTransform; // make a stripped down copy of the Text var go = GameObject.Instantiate(transform, transform.position, transform.rotation) as Transform; foreach (var component in go.GetComponents()) { if (component is Text) continue; else GameObject.Destroy(component); } go.SetParent(transform.parent); // make sure transform has original values go.localScale = transform.localScale; var TextComponent = go.GetComponent(); TextComponent.rectTransform.sizeDelta = transform.sizeDelta; // use the copy to create an underline TextComponent.text = new System.Text.RegularExpressions.Regex(".").Replace(TextComponent.text, "_"); } }

Answer by vladipus

$
0
0
Using a combination of OLP's and ikn's answers: if (GUILayout.Button( "Do Stuff", EditorStyles.label, GUILayout.ExpandWidth(false))) { DoStuff(); } var lastRect = GUILayoutUtility.GetLastRect(); GUI.Label(lastRect, "___________"); If this doesn't work for you try increasing and decreasing the number of underscores in the last label.
Viewing all 18 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>