Game Development Reference
In-Depth Information
Now ain't that pretty? However, looking at the full picture and the game view,
it still looks pretty much the same as a
Screen Space - Overlay
canvas. So let's
do something about this.
In one test I sized both the
Background
and the
Fill Area
Rect
Transform's to fill the entire of the
Slider
Rect Transform size.
Just a thought, makes them bigger and easier to handle.
Reaching in
So we've got our fancy slider bars in play, but it still looks flat. To break this
perception, we need to add some perspective and to do this we need a new
Camera
.
Without a separate camera, the
Screen Space - Camera
Canvas still operates exactly
like a
Screen Space - Overlay
Canvas, as there is nothing to tell it how to draw
differently. So let's add one.
Create a new
Camera
in the scene (
Create
|
Camera
) and name it
GUICamera
.
The first thing you will notice (especially if you look at the game view) is that our
scene has now vanished! Well, almost everything, the new
UI
we created is still
shown. This is simply because both the new
Camera
you created and the
Main
Camera
attached to the ship are both competing to draw to the same render depth,
Depth
0
, as shown in the
Camera
properties. Because the new
GUICamera
is at the
bottom of the project hierarchy, it is drawn last and wins.
Remember, in Unity 4.5, Unity Technologies changed how the rendering
chain worked. Elements are now drawn according to the order they
appear in the project
Hierarchy
, which by default is normally alphabetic.
Now, as this
Camera
is going to be specifically used for
UI
rendering, we can update
its options to focus on just
UI
elements.
If you plan to use multiple
Screen Space - Camera
Canvases (which is
possible), each with their own
Camera
, be sure to use separate
Layers
for each canvas unless you want them to draw each other! A fascinating
bug that showed up while creating the demo scene, which saw my
World
Canvas
UI flying along in the background of the scene. This was because
it was drawing on the same layer as my
Main Camera
, which was very
weird to see.