Game Development Reference
In-Depth Information
A word on RawImage
Alongside the
Image
control is the
RawImage
control. The only difference between
the two is that the
RawImage
uses a
Texture
instead of a
Sprite
as its
Source
(the
Texture
property in this case).
Apart from the advanced texture import settings, the big advantage here is that
you could use this to display images downloaded from the Web (once you have
downloaded it), since there are functions to turn a downloaded image stream
into a
Texture
.
Don't push this button
As we venture into the interactive realm, we tackle the first of the combined controls,
the
Button
control/component. In fact, the
Button
control is not a single entity but a
combination of several different components under one banner. The
Button
is more
of an example of what can be achieved by building/combining controls to do what
you want more than anything else.
Like with the previous controls, you can add the
Button
from the menu or through
the project
Hierarchy
, or using the component options (
Create
|
UI
|
Button
).
When you add a
Button
control, what you actually get is the following:
• An
Image
control
• A
button
script that implements:
° The
Selectable
control (covered later)
° Several
Trigger
events
• A
Text
control (as a child)
A fairly well-built stack that draws in all the features it needs. In fact, let's look at the
Button
control in code:
Note: This is taken directly from the UI source as an example.
If you add this in a project it will cause an error because there is
already a
Button
control/class!
using System;
using System.Collections;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.Serialization;