--the below script will make a UIToggle disable/enable Rich Text support in the UIText--[Add "toggle" and "text" references to the Scripting Runtime component]thisGameObject = Space.Host.ExecutingObjecttoggle = Space.Host.GetReference("toggle").UIToggle text = Space.Host.GetReference("text").UIText text.Text ="<b> Bold Test </b>"OVC=function()if toggle.IsOn then text.SupportRichText =trueelse text.SupportRichText =falseendendtoggle.OnValueChanged(OVC)
--the below script will make a UIToggle disable/enable the Best Fit feature in the UIText--[Add "toggle" and "text" references to the Scripting Runtime component]thisGameObject = Space.Host.ExecutingObjecttoggle = Space.Host.GetReference("toggle").UIToggle text = Space.Host.GetReference("text").UIText text.Text ="A very long text a very long text a very long text a very long text"OVC=function()if toggle.IsOn then text.ResizeTextForBestFit =trueelse text.ResizeTextForBestFit =falseendendtoggle.OnValueChanged(OVC)
--the below script will make a slider change the UIText's Best Fit Min Size--[Add "slider" and "text" references to the Scripting Runtime component]thisGameObject = Space.Host.ExecutingObjectslider = Space.Host.GetReference("slider").UISlidertext = Space.Host.GetReference("text").UIText text.Text ="Best Fit Min Size"text.ResizeTextForBestFit =trueOVC=function()text.ResizeTextMinSize = (slider.Value *20) +10-- from 10 to 30endslider.OnValueChanged(OVC)
--the below script will make a slider change the UIText's Best Fit Max Size--[Add "slider" and "text" references to the Scripting Runtime component]thisGameObject = Space.Host.ExecutingObjectslider = Space.Host.GetReference("slider").UISlidertext = Space.Host.GetReference("text").UIText text.Text ="Best Fit Max Size"text.ResizeTextForBestFit =trueOVC=function()text.ResizeTextMaxSize = (slider.Value *50) +20-- from 50 to 70endslider.OnValueChanged(OVC)
AlignByGeometry
bool AlignByGeometrygetset
Use the range of glyph geometry to perform horizontal alignment.
--the below script will make a UIToggle disable/enable the Align By Geometry feature in the UIText--[Add "toggle" and "text" references to the Scripting Runtime component]thisGameObject = Space.Host.ExecutingObjecttoggle = Space.Host.GetReference("toggle").UIToggle text = Space.Host.GetReference("text").UIText text.Text ="Align By Geometry"OVC=function()if toggle.IsOn then text.AlignByGeometry =trueelse text.AlignByGeometry =falseendendtoggle.OnValueChanged(OVC)
FontSize
int FontSizegetset
The size that the Font should render at.
Space.Host.ExecutingObject.UIText.FontSize =54
--the below script will make a slider change the UIText's Font Size--[Add "slider" and "text" references to the Scripting Runtime component]thisGameObject = Space.Host.ExecutingObjectslider = Space.Host.GetReference("slider").UISlidertext = Space.Host.GetReference("text").UIText text.Text ="Text Size Test"OVC=function()text.FontSize = (slider.Value *40) +10-- from 10 to 50endslider.OnValueChanged(OVC)
LineSpacing
float LineSpacinggetset
How much space will be in-between lines of text. This is a multiplier. The line spacing value set will be multiplied by the font's internal line spacing. A value of 1 will produce normal line spacing.
--the below script will make a slider change the UIText's Line Spacing--[Add "slider" and "text" references to the Scripting Runtime component]thisGameObject = Space.Host.ExecutingObjectslider = Space.Host.GetReference("slider").UISlidertext = Space.Host.GetReference("text").UIText text.Text ="Line Spacing Line Spacing Line Spacing Line Spacing Line Spacing"OVC=function()text.LineSpacing = (slider.Value *2) -- from 0 to 2endslider.OnValueChanged(OVC)
PixelsPerUnit
float PixelsPerUnitget
Provides information about how fonts are scale to the screen.
For dynamic fonts, the value is equivalent to the scale factor of the canvas. For non-dynamic fonts, the value is calculated from the requested text size and the size from the font.
thisObject = Space.Host.ExecutingObject--get a reference to our objectthisObjectText = thisObject.UIText--get a reference to the UIText component in our object Space.Log(thisObjectText.PixelsPerUnit)--Prints the PixelsPerUnit value of this UIText component to the console
MinWidth
float MinWidthget
The minimum width this UIText may be allocated. (Used by the Layout system).
thisObject = Space.Host.ExecutingObject--get a reference to our objectthisObjectText = thisObject.UIText--get a reference to the UIText component in our object Space.Log(thisObjectText.MinWidth)--Prints the MinWidth value of this UIText component to the console
PreferredWidth
float PreferredWidthget
The preferred width this UIText should be allocated if there is sufficient space. (Used by the Layout system)
Whether the UIText component is Enabled or not will decide if it is visually updating or not.
Space.Host.ExecutingObject.UIText.Enabled =true
--this below script will make clicking this object disable/enable a UIText componentthisGameObject = Space.Host.ExecutingObjecttext = Space.Host.GetReference("text").UITextOnClick=function()if text.Enabled then text.Enabled =falseelse text.Enabled =trueendendthisGameObject.AddClickable()thisGameObject.Clickable.Tooltip ="click to hide/show text"thisGameObject.Clickable.OnClick(OnClick)
--the below script will make a UIText element with this script--constantly update itself to show the local time--(Example: UI Text element that shows local clock)--[This object needs to be a UI Text object. In Unity, Heirarchy -> Create -> UI -> Text]--<Note: UI Text element could also be in world space if it's canvas is a world space canvas>thisGameObject = Space.Host.ExecutingObjectOnUpdate=function()thisGameObject.UIText.Text = Space.LocalTimeendthisGameObject.SubscribeToEvents()thisGameObject.OnUpdate(OnUpdate)
--This script dynamically changes the text's color of a GameObject with UIText component.--For example in a text sign over your shop that you want to make more visually stand out--or perhaps text decoration during a celebration or a text element in your User Interface or HUD.thisObject = Space.Host.ExecutingObject--get a reference to our objectthisObjectText = thisObject.UIText--get a reference to the SUIText component in our object colors = {Color.Red, Color.Black, Color.White, Color.Blue, Color.Green, Color.Yellow}--here we are holding 6 predefined colors in a Lua Table which we will go throughfunctionColorChanger()whiletruedo--infinite loopfor i=1,#colors do--For Loop to cycle through all the table items thisObjectText.color = colors[i] --this will set the color based on which item in the table we are now atcoroutine.yield(0.1)--this will pause for a tenth of a second before we change to the next colorendendendSpace.Host.StartCoroutine(ColorChanger) --this coroutine will now call our ColorChanger() function which is infinitely changing our text colors between a select range.