Game Development Reference
In-Depth Information
3. Next, create the new
GUITexture
object by going to
GameObject
|
Create Other
|
GUI Texture
and name it as
RocketUI
. Next, we drag our
RocketUI
script, which
we just created on this object. Then set the following:
Transform
:
Position
:
X: 0.91
,
Y: 0.08
,
Z: 0
GUITexture
:
Texture
:
rocketUI
(Drag the
rocketUI.png
in the
Chapter5/UI
folder
from the
Project
view here)
Pixel Inset
:
X: -64
,
Y: -32
,
Width: 128
,
Height:
64
Rocket UI (Script)
Rocket Launcher
:
RocketLauncher
(Drag
RocketLauncher
child of the
First
Person Controller
here)
Custom Skin
:
CustomSkin
(Drag the
CustomSkin
that we just created in the
Project
view here)
We are now done with this chapter. We can click
Play
to see the result, and now if we press
the
R
key to reload the bullet, we will see the number changes to 20 as we set the maximum
number of bullets.
Objective Complete - Mini Debriefing
We just created the UI to show the rocket graphics UI and the number of bullets left by using
GUITexture
and
OnGUI()
. Here, we also created the text with a shadow by drawing another
text layer and shiting the posiion botom-right 2 pixels each, and then we drew the top
layer by using the default posiion and color.
Classified Intel
In Unity, there is no easy way to create an outline or shadow for the dynamic text that can be
easily adjustable like other software such as Flash, Photoshop, and so on. So we can create
it by drawing another layer to act as the outline of the shadow, as we did for the onGUI()
funcion in this chapter.
This is not the best way to create the outlined text or the shadow text because if we adjust the
size of the pixel by shifting more than 2 pixels, we will see that the background text shifts too
much and doesn't look like the outline or shadow, as we can see in the following screenshot: