Version: 2017.3
public int fontSize ;

描述

Font 渲染时应使用的大小。

这是 Text 的 Font 的大小。可用于提取或更改 Font 的大小。更改 Font 的大小时,请记得考虑 Text 的 RectTransform。过大的 Font 或过长的消息可能不适合某些矩形的大小,无法在 Scene 中显示。

//For this script to work, create a new Text GameObject by going to Create>UI>Text. Attach the script to the Text GameObject. Make sure the GameObject has a RectTransform component.

using UnityEngine; using UnityEngine.UI;

public class Example : MonoBehaviour { Text m_Text; RectTransform m_RectTransform;

void Start() { //Fetch the Text and RectTransform components from the GameObject m_Text = GetComponent<Text>(); m_RectTransform = GetComponent<RectTransform>(); }

void Update() { //Press the space key to change the Font size if (Input.GetKey(KeyCode.Space)) { changeFontSize(); } }

void changeFontSize() { //Change the Font Size to 16 m_Text.fontSize = 30;

//Change the RectTransform size to allow larger fonts and sentences m_RectTransform.sizeDelta = new Vector2(m_Text.fontSize * 10, 100);

//Change the m_Text text to the message below m_Text.text = "I changed my Font size!"; } }