- Home /
Question by
teopotter88 · Oct 10, 2016 at 07:39 AM ·
fontfont-size
Changing the font and size of GUI Text
How can I change the font and the font size of GUI text?
Comment
Answer by teopotter88 · Oct 10, 2016 at 10:36 AM
I meant GUI text with coding.
using UnityEngine; using System.Collections;
public class OnCollision : MonoBehaviour {
public Transform other;
void OnGUI() {
if (other) {
float dist = Vector3.Distance(other.position, transform.position);
if(dist < 15 ){
GUI.Button(new Rect(600, 100, 100, 100), "NO");
GUI.Button(new Rect(800, 100, 100, 100),"YES");
GUI.TextArea(new Rect (600, 250, 300, 100), "Do You Want To Open This Crate?");
}
}
}
}
So this is my code to create 2 GUI buttons and GUI text on collision. I want to change the font, font size, and the position of the GUI text. How can I do it.
Answer by doublemax · Oct 10, 2016 at 10:39 AM
All GUI methods also have an overload that takes a GUIStyle as parameter, You can modify that by script or, if you make it public, you can edit it easily in the inspector.