Unity3D – Tutorials – UI – Responsive Text

This feature is avaiable for Unity3D 4.6 or above.

Create Objects

1. Open Unity3D and create:

– MAIN TOP MENU> GameObject> Camera, name it ‘Main Camera’
– MAIN TOP MENU> GameObject> UI> Canvas
– MAIN TOP MENU> GameObject> UI> Text

NOTICE: Canvas will be created inside Layer UI

NOTICE: In the Hierarchy there is:
– Canvas
-> Text (it is the child of Canvas)
– EventSystem

Setup Viewports and Tools

2. 3D Viewport select orthographic X View
3. TOP LEFT> TOOLS> Canvas Manipulation icon
4. Game Viewport> 4:3

Canvas Setup

Hierarchy> Canvas> Inspector>

>Canvas
– Render Mode> Screen Space – Overlay
– Pixel Perfect: check

>Canvas Scaler
– Ui Scale Mode: Scale With Screen Size
– Reference Resolution: 800×600
– Screen Match Mode: Match Width or Height

Text Setup

Hierarchy> Text> Inspector>

>Rect Transform>
– Pos X=0 Y=0 Z=0
– Width=800 Height=800 (The same of Canvas Scaler> Reference Resolution)
– Anchor Preset Button (the square icon on top left with a target): middle center

>Text (Script)
– Text: type your text
– Font: WARNING! Include the font inside your Project Window, to include it inside the final Build
Unity supports: TrueType, OpenType, DaFont.
– Font Size: setup the size of the font
– Horizontal Overflow: Wrap (per andare a capo automaticamente)
– Vertical Overflow: Truncate (per non scrivere al di fuori dell’area visibile)
– Best Fit: check (Font Size sarà scelta automaticamente per essere visibile ad ogni risoluzione, si può fornire anche un valore tra Min Size e Max Size)
– Color: Setup the color

Dynamic Text – JS

Hierarchy> Text> Inspector> Add Component> New Script> DynamicText.js


#pragma strict

var theTextComponent : UI.Text; // ASSIGN IN INSPECTOR!!!

function Awake () {
}

function Start () {
theTextComponent.text = "My Super Text";
}

function Update () {
}

Hiearchy> DRAG AND DROP Text into Inspector var ‘theTextComponent’