- Home /
Question by
teopotter88 · Oct 11, 2016 at 07:52 AM ·
font size
Changing Font Size of GUI Text With Code?
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?");
}
}
}
}
This is my current code. How can i implement the fontSize variable to change the font size of the text in the GUI.TextArea and GUI.Buttons?
Comment
Answer by doublemax · Oct 11, 2016 at 07:59 AM
Didn't i answer that already yesterday?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GUITest : MonoBehaviour
{
public Transform other;
public GUIStyle style;
void OnGUI()
{
if (other)
{
float dist = Vector3.Distance(other.position, transform.position);
if(dist < 15 )
{
GUI.Button(new Rect(600, 100, 100, 100), "NO", style);
GUI.Button(new Rect(800, 100, 100, 100),"YES", style);
GUI.TextArea(new Rect (600, 250, 300, 100), "Do You Want To Open This Crate?", style);
}
}
}
}
https://docs.unity3d.com/540/Documentation/ScriptReference/GUIStyle.html
You can modify the GUIStyle variable comfortably in the inspector.
Your answer
![](https://koobas.hobune.stream/wayback/20220612094413im_/https://answers.unity.com/themes/thub/images/avi.jpg)