Game Development Reference
In-Depth Information
Rather than changing each sprite individually, we can easily adjust the sprites
in bulk by performing the following steps:
1.
Select all of your cloud layer sprites, and under their
Sprite Renderer
components, set their
Order in Layer
to
0
.
2.
Set the
Order in Layer
property of the
_NearHillsLayer
sprites to
1
and that
of the
_FarHillsLayer
sprites to
0
.
3.
Select the Prefab named
Platform
and set its
Order in Layer
to
2
; you should
see all of your
Platform
sprites instantly update in the scene.
4.
Set the
Order in Layer
values of the Prefabs for
Enemy
and
Player Bullet
to
2
.
5.
Set the sprite on the
Player
object in the scene to
2
as well.
6.
Finally, set the
Wall
objects to
3
and you're good to go.
With the layers all set up, let's finish setting up the parallax layers. First, finish placing
any additional parallax sprites; I'll wait. Brilliant! Now, go to the
_ParallaxLayers
object and let's play around with that
Parallax Controller
component. We're going
to want to add all of those sprites to
Parallax Controller
. To make this easy, look at
the top-right corner of the
Inspector
panel. See the little lock icon? Click on it. Now,
regardless of what you do, the
Parallax Controller
component will not be deselected.
Since it can't be deselected, you can now easily drag-and-drop all of the
Cloud
sprites into the
Clouds
array in the ParallaxController component, and all of the
_FarHillsLayer
child objects into the
Far Hills
array—you see where this is going.
Set the
My Camera
field to use the
Main Camera
object. Finally, let's set some values
in those
Layer Speed Modifier
fields. The higher the number, the faster the object
will move as the camera moves. As an example, we set the
Cloud
layer to
0.05
, the
Near
layer to
0.2
, and the
Far
layer to
0.1
. Feel free though to play with the values
and see what you like!
Go ahead and play the game. Click on the play button and watch those layers move!
But, what's this? The particles that burst when an enemy is defeated render behind
the sprites in the background—actually, they render behind all the sprites! To fix
this, we need to tell Unity to render the particles on a layer in front of the sprites.
By default, the sprites render after the particles. Let's change that.