Skip to content

Text

extends Control

The Text class allows for easy display of text information in a game, such as game scores, player names, item names, etc.

You can obtain a Text component using the following method:

typeScript
let go = new GameObject("ui");
let uiComponent = go.AddComponent<UIComponent>(UIComponent);
let canvas = uiComponent.canvas;		
let text = canvas.FindChild<Text>("Text");

成员变量

Text.text : string
The content of the text.
Text.richText : boolean
Rich text for text display.
Text.maxSize : number
The maximum font size of the text.
Text.bestFit : boolean
Whether the text adapts its size.
Text.material : Material|null
The material used for text rendering.
Text.raycastTarget : boolean
Whether the text responds to raycast detection.
Text.transferred : boolean
Whether the text can be escaped.
Text.horizontalOverflow : boolean
Whether the text is in horizontal overflow mode.
Text.alignByGeometry : boolean
The geometric alignment mode of the text component.
Text.verticalOverflow : boolean
Whether the text is in vertical overflow mode.
Text.fontSize : number
The font size of the text.
Text.minSize : number
The minimum font size for the text.
Text.outline : number
The width of the text outline.
Text.lineSpacing : Vector2
Line spacing of the text.
Text.hAlignment : TextHAlignment
Index value of the font style.
Text.offset : Vector2
The offset of the text.
Text.color : Color
Text color.
Text.backgroundTexture : Texture|null
The background texture of the text.
Text.vAlignment : TextVAlignment
The vertical alignment of the text.
Text.backgroundColor : Color
The background color of the text.
Text.outlineColor : Color
The outline color of the text.
Text.fontName : string
The name of the font used for the text.
Text.fontStyle : number
The font size of the text.
Text.font : ``
The font of the text.