Game Development Reference
In-Depth Information
Now for the start button! Add another empty GameObject, name it
Start Button
,
and place it inside the
Container - Start
object. Give them both an
Order in Layer
property of
100
, and make sure they are both in the exact same location with the
exact same scale. Add a
Box Collider 2D
component on the
Start Button
object
itself, and make sure the collider completely surrounds the button imagery inside.
The
Box Collider 2D
component will actually allow the StartButtonController script,
which we will write in a couple pages, to accept mouse events.
Your hierarchy should now look a little something like the following screenshot:
If you're worried that the gameplay elements—enemies and the player—could
collide with the UI, then you have a very valid concern! Addressing this is easy.
First, add a new layer called
UI
. Now, set all of the UI elements to the
UI
layer.
Finally, adjust
Physics 2D
Layer Collision Matrix
in the physics settings, just like
before, to prevent collisions. After you edit the matrix, you'll have a setup that looks
like the following screenshot: