Game Development Reference
In-Depth Information
If you wish, you can now go back to the
Slider
and stretch the
Anchors
for the
Background
and
FillArea
GameObjects to make
them fill the entire Slider.
The designer asked for 20-pixel distance between the top of the screen and the health
bar, but at present, it's actually about 9 pixels from the top. (Why oh why? It's set to
20 in the preceding screenshot, isn't it!)
The reason is simple if you recall from earlier: the
Anchors
are positioned relative to
the
Pivot
point of the
Rect Transform
, and our
Pivot
is still set to the default, in the
center of our
Slider
J
.
To correct this, include half the height of the Slider's GameObject in your
Pos Y
value of the Slider's
Rect Transform
(it's negative because we are counting from the
top of the screen), edit the
Pivot
point to be at the top of the
Slider
by setting the
value of
Pivot
Y
to
1
, or use the
Rect Tool
in
Pivot
mode and drag the
Pivot
point
(blue circle) to the top of the
Rect Transform
(which is what I did in this example).
Just be sure to check that the
Pos Y
value is correct after editing the
Pivot
point and that it hasn't moved the
Rect Transform
. If it has,
then update it again to
-20
.
So we have met our goal; time to get paid, right? Actually, no because our designer
simply failed to mention one little thing: it's meant to also run on a 4-inch Android
device. This means our previous settings will not scale down enough and our health
bar will not be drawn all because the left and right padding values are set to
200
.
When the screen is scaled down, there won't be enough space left to draw the
slider, whoops!
Note, you do not have to use just the
Anchor Presets
. If you wish
you can also alter the
Anchors
manually by dragging each corner
of the
Anchor
handle to the position you wish. In most cases the
presets are enough but if you want more, you can just Do it Yourself!