- Home /
How do I change the font and color of GUI text?
I have a (still unfinished) script that shows text when you enter a trigger, but right now it's just white text in the Arial font. How do I change the color and the font to one of the fonts I imported. (And is it possible to add a shadow or outline to the text?)
var buttonInRange;
var buttonActivated;
var amount : float = 0;
var CamTimer : CamTimer;
private var hasPlayed = false;
function OnTriggerEnter (c : Collider)
{
buttonInRange = true;
}
function OnTriggerExit (c : Collider)
{
buttonInRange = false;
}
function OnGUI ()
{
if(buttonInRange == true)
{
GUI.Label (Rect (Screen.width/2-50, Screen.height/2-55, 120, 50), "Pick up battery");
if (buttonInRange == true)
{
if (Input.GetKeyDown ("e"))
{
GUI.Label(Rect(155, 100, 75, 23), "Batteries: " + amount.ToString("1"));
}
}
}
}
function Update ()
{
if (buttonInRange == true)
{
if (Input.GetKeyDown ("e"))
{
Destroy(gameObject);
hasPlayed = true;
}
}
}
Comment
Answer by Graham-Dunnett · May 24, 2014 at 11:43 AM
You'll want to read up on GUISkin
and GUIStyle
. A GUIStyle
can be marked as having rich text, which supports colouring of the string. See:
http://docs.unity3d.com/Documentation/ScriptReference/GUIStyle.html
Your answer
Follow this Question
Related Questions
How do I change the font and color of GUI text? 0 Answers
Script loads font, how do I change the color? 2 Answers
Color.white not so much white... 3 Answers
GUI text font change 3 Answers
Gui text script - help 1 Answer