- Home /
How To change guiText's font dynamically in runtime(or) by script?
Hi, Everybody I m facing a problem in changing guitext font dynamically? I didnt found any solution yet on the net. Is there any solution? Please.
Answer by JMAA · Oct 10, 2012 at 11:53 AM
Try to create first the font materials you need your guiText's set to, and then use this bit of script:
//Make sure this array is set with the fonts you need in the inspector!!
public var fontMat : Material[];
//This is where you set the default font
function Start () {
renderer.material = fontMat[0];
}
//To set default again
function FontDefault () {
renderer.material = fontMat[0];
}
//Use I.E: ChangeFont(2) to change to the second set font
function ChangeFont (id : int) {
renderer.material = fontMat[id];
}
//This is where you set the default font
function Start () {
}
function ChangeFont () {
}
Someone hopefully will know a more straight way of changing the font here, but the fonts always depend on font materials AFAIK.
Answer by fafase · Oct 10, 2012 at 11:37 AM
It is in the docs actually:
Declare as many variables as you need, you might want to create an array. Then simply assign the appropriate one.
var font1:Font;
var font2:Font;
guiText.font = font1;
guiText.font = font2;
Thank you so much fasfase.Actually, I would like to know how to load (or) access installed font.
You might want to have a look at the Resources class. http://docs.unity3d.com/Documentation/ScriptReference/Resources.html
Your answer
![](https://koobas.hobune.stream/wayback/20220613082129im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Canvas Text gets garbled 0 Answers
Need urgent help with dynamic font not working on Mac! 1 Answer
GUIText doesnt show after changing font 1 Answer
Changing GUIText.font on runtime 1 Answer
Using fonts in Unity - iOS devices 2 Answers