Game Development Reference
In-Depth Information
Objective Complete - Mini Debriefing
We just inished creaing a
restart
buton for our plaform game. We used
Destroy
and
Instantiate
to remove and create a new clone of the object from the prefab. We also
added a sound efect to our restart buton and character. Then, we set
audio.volume
to
1.0;
to set the volume of our sound effect and used
audio.PlayOneShot(AudioClip);
to play a sound effect once it is triggered.
Classified Intel
In
restartButton
, we can also add
Application.LoadLevel(LevelName)
to
reset our game, which is much easier than using
instantiate
, but the
Application.
LoadLevel
will destroy all the game objects in the scene and reload again. In this case, we
use
instantiate
in our game because we only have one scene and don't want to load the
whole game level again. However, we can also put
DontDestroyOnLoad()
in the
Awake()
funcion of the object that we don't want to destroy, but it needs a bit of setup. So, there is
no right or wrong. It depends on what we want to use or where we want the project to go.
Game over-Wrapping it up
We just created a simple 2D plaform game, and it is our irst piece to get started with Unity.
In this chapter, we have learnt how to manage a sprite animaion by adjusing the
Tiling
and
Offset
of the material. We have gone through the
MonoDevelop
scriping editor and
created a JavaScript class. Also, we have learnt the basics of how to use
Input Manager
,
Physics Raycast
,
Gizmos
, and
Collider
. Finally, we have atached the sound efect and a
restart
buton to our game. Let's take a look at what we have: