Unity3D – Tutorials – UI – Scroll Rect – Text

Unity3D – Tutorials – UI – Scroll Rect – Text

Inside a Scrool Rect you can scroll a text greater than the Scroll Rect Area.

Scrool Rect – Yes ScroolBars

0. MAIN TOP MENU> GameObject> UI> Canvas

1. MAIN TOP MENU> GameObject> UI> Text

2. MAIN TOP MENU> GameObject> Empty Object, rename it ScrollRectObj

3. Hierarchy> select ScrollRectObj> Inspector> ‘Add Component’
> Scroll Rect (Transform component will be authomatic removed)
> Image
> Mask

4. Parent as show below:

– Canvas
-> ScrollRectObj (child of Canvas)
->> Text (child of ScrollRectObj)

5. Setup size and position:

– Inspector> ScrollRectObj: Width= 100 Height= 100 Pos XYZ= 0,0,0

– Inspector> Text: Width= 100 Height= 400 Pos XYZ= 0,0,0

The Text is greater than ScrollRectObj and it will scroll from top to bottom

6. Setup ScrollRectObj

– Inspector> ScrollRectObj> Scroll Rect (Script)> Content, DRAG AND DROP from ‘Hierachy> Text’ here

7. Vertical Scroll Bar

a. Hierarchy> RMB over Canvas> UI> Scrollbar

– Canvas
-> ScrollRectObj (child of Canvas)
->> Text (child of ScrollRectObj)
-> Scrollbar (MUST BE CHILD OF CANVAS)

b. Hierarchy> select Scrollbar DRAG AND DROP Inspector> ScrollRectObj> Scroll Rect (Script)> Vertical Scrollbar

c. Inspector> ScrollBar> Rect Transform> Rotation Z=90
OR
c. Inspector> ScrollBar> Scrollbar (Script)> Direction> Top To Bottom

3. Play and enjoy!

By |Unity3D, Video Games Development|Commenti disabilitati su Unity3D – Tutorials – UI – Scroll Rect – Text

Unity3D – Tutorials – UI – Scroll Rect – Image

Unity3D – Tutorials – UI – Scroll Rect – Image

Inside a Scrool Rect you can scroll an image greater than the Scroll Rect Area.

Scrool Rect – No ScroolBars

0. MAIN TOP MENU> GameObject> UI> Canvas

1. MAIN TOP MENU> GameObject> UI> Image

2. MAIN TOP MENU> GameObject> Empty Object, rename it ScrollRectObj

3. Hierarchy> select ScrollRectObj> Inspector> ‘Add Component’
> Scroll Rect (Transform component will be authomatic removed)
> Image
> Mask

4. Parent as show below:

– Canvas
-> ScrollRectObj (child of Canvas)
->> Image (child of ScrollRectObj)

5. Setup size and position:

– Inspector> ScrollRectObj: Width= 100 Height= 100 Pos XYZ= 0,0,0

– Inspector> Image: Width= 200 Height= 200 Pos XYZ= 200,0,0

The Image is greater than ScrollRectObj and in a different position

6. Setup ScrollRectObj

– Inspector> ScrollRectObj> Scroll Rect (Script)> Content, DRAG AND DROP from ‘Hierachy> Image’ here

Play, Image will be moved inside ScrollRectObj, DRAG the image to move it

WARNING: the best practice is put the Image already inside the Scrool Rect, then please modify:
Inspector> Image: Width= 200 Height= 200 Pos XYZ= 0,0,0

Scrool Rect – Yes ScroolBars

1. Hierarchy> RMB over Canvas> UI> Scrollbar

– Canvas
-> ScrollRectObj (child of Canvas)
->> Image (child of ScrollRectObj)
-> Scrollbar (MUST BE CHILD OF CANVAS)

2. Hierarchy> select Scrollbar DRAG AND DROP Inspector> ScrollRectObj> Scroll Rect (Script)> Horizontal Scrollbar

3. Play and enjoy!

By |Unity3D, Video Games Development|Commenti disabilitati su Unity3D – Tutorials – UI – Scroll Rect – Image

Unity3D – Tutorials – UI – Responsive Slider

Unity3D – Tutorials – UI – Responsive Slider

The Event System check the user input over the Canvas elements.

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> Slider

NOTICE: Canvas will be created inside Layer UI

NOTICE: In the Hierarchy there is:

– Canvas
-> Slider
->> Background
-> Fill Area
->> Fill
-> Handle Slide Area
->> Handle

– 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

Slider Setup

Hierarchy> Slider> Inspector>

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

Play and try resize the Game Viewport

Event Listener

1. Hierarchy> select Slider> Inspector> Slider (Script)> +>
– Interactible> check (true)
– DRAG AND DROP into empty slot> Main Camera
– ON THE RIGHT rollout> Camera> fieldOfView

2. Slider (Script)> Min Value=1 Max Value=179

Eligible Functions

Functions that return a FLOAT value

Slider as Energy Bar – Graphic Setup

Hierarchy> Canvas> Slider> Background> uncheck, it removes the background OR simple change color to green

Hierarchy> Canvas> Slider> Fill Area> Fill> change color to red

Hierarchy> Canvas> Slider> Handle Slide Area> Handle> uncheck, it removes the handle

Slider as Energy Bar – JS

Slider (Script)> Interactable> uncheck (false)

1. Hierarchy> Slider> Add Component> New Script> EnergyBar.js


#pragma strict

var theSliderComponent : UI.Slider; // ASSIGN IN INSPECTOR!!!

function Awake () {
}

function Start () {
}

function Update () {
theSliderComponent.value = Mathf.MoveTowards (theSliderComponent.value, 100.0f,0.15f);
}

2. Hierarchy DRAG AND DROP Slider over Inspector> EnergyBar.js> var theSliderComponent

3. Play :)

By |Unity3D, Video Games Development|Commenti disabilitati su Unity3D – Tutorials – UI – Responsive Slider

Unity3D – Tutorials – UI – Event System

Unity3D – Tutorials – UI – Event System

The Event System check the user input over the Canvas elements.

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> Button

NOTICE: Canvas will be created inside Layer UI

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

Setup Viewports and Tools

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

Event System Setup

1. Hierarchy> DRAG AND DROP Button over Inspector> Event System (Script)> First Selected empty slot

2. Play> See below the Inspector, you can see the EventSystem data in real time

Event Trigger

With Event Trigger you can listen user input actions over Images, Text or other Gameobjects.

1. MAIN TOP MENU> GameObject> UI> Text

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

2. Attacch to Text MyScript.js:


#pragma strict

function Start () {
}

public function MyFunction(){
Debug.Log ("Pointer has entered");
}

function Update () {
}

3. Hierarchy> select Text> Inspector> ‘Add Component’> Event Trigger

4. Event Trigger> ‘Add New Event Type’> Pointer Enter> +>
a. DRAG AND DROP Text over the Empty Slot
b. click the rollout ON THE RIGHT> MyScript> MyFunction

5. Play and move the pointer over the Text.

Elegible Functions

NOTICE: a function will be elegible if is – public void MyFunction() – and have none or 1 parameter.

public: deve essere pubblica, cioè poter essere letta al di fuori dello script originale
void: non restituisce un valore di ritorno, non ammette il comando – return –

The parameter can be in C#:

– public void MyFunction()
– public void MyFunction(float MyFloat)
– public void MyFunction(int myInt)
– public void MyFunction(string myString)
– public void MyFunction(bool myBool)
– public void MyFunction(Object myObject) -> Unity Object

The parameter can be in JS:

– public function MyFunction()
– public function MyFunction(float MyFloat)
– public function MyFunction(int myInt)
– public function MyFunction(string myString)
– public function MyFunction(bool myBool)
– public function MyFunction(Object myObject) -> Unity Object

Events

– Pointer Enter
– Pointer Exit
– Pointer Down
– Pointer Up
– Pointer Click
– Drag
– Drop
– Scrool
– Update Selected
– Select
– Deselect
– Move
– Initialize Potential Drag
– Begin Drag
– End Drag
– Submit
– Cancel

By |Unity3D, Video Games Development|Commenti disabilitati su Unity3D – Tutorials – UI – Event System

Unity3D – Tutorials – UI – Responsive Text

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’

By |Unity3D, Video Games Development|Commenti disabilitati su Unity3D – Tutorials – UI – Responsive Text