Game Development Reference
In-Depth Information
Building the shop scene
To make the best use of the new 2D system, we can create a new scene to place the shop-
ping interface for the player to use; so we'll create a new scene named
Shop
.
With this in place, just copy the assets from the sample assets pack accompanying this
title for the shop interface into your project's
Assets
folder (
ShopScreen
images for
the environment and
BackButton
,
BuyButton
, and
Weapon Icons 1
images for
props). Then, drag the
ShopScreen
image on to the new scene and check that the new
game object is called
ShopScreen
. Additionally, ensure that the sprite-sorting layer for
each of the sprite renderers is appropriate so that they get drawn in front; to do this, set all
of them to the foreground layer.
Note
The
Weapon Icons 1
image is a spritesheet, so remember you'll need to set its
SpriteMode
option to multiple and splice it with
Sprite Editor
. Each image is of 32 x 32
pixels.
As we are using the 2D system for the shop screen, we have greater flexibility to design
the screen without using Unity's native GUI system.
Note
Unity is soon going to release a new GUI system in Version 4.6, which could be used to
replace what we are building here; however, currently it is not available. Nevertheless,
this section is written so that it will be easily translatable and you'd not need to replace the
code of the current GUI framework.
So first, we need to create some empty game objects to place all the UI elements we need
on the screen, adding the following assets as children of the
ShopScreen
game object:
•
BackButton
: This object will capture when the user wants to exit the screen
•
OwnerSlot
: This object is a place to display the sprite of the shop's owner
•
Slot01
and
Slot06
: These objects are the available shop inventory slots
•
PurchasingSection
: This object is an empty grouping game object; it is used so
that we will be able to enable/disable all the purchasing options together
•
BuyButton
: This object captures when the user wants to purchase an item; it is
attached to the
PurchasingSection
object