Summary
In this chapter, you built a unique collectible game object using primitives and basic materials, saved it to a prefab, and made its instantiations collectible and savable.
You collected coins by calling Unity's GetComponent
function from the coin's script to access a collection script on the player. GetComponent
is an extremely useful tool in the Unity engine that allows for substantial communications between two unrelated game objects, so get used to using it.
Finally, you scripted a system that counts the number of coins collected from each play session and adds them to a running total that's loaded every time the game starts. Incorporating save data into your game is essential to expanding your game's scope as it allows you to potentially develop a narrative and skill progression over several sessions rather than giving the player a short, one-shot repetitive experience such as Solitaire.
Next, we'll expand your game further by creating unlockable content that can be purchased by...