Book Image

Unity Game Development Scripting

By : D'Aoust
Book Image

Unity Game Development Scripting

By: D'Aoust

Overview of this book

The intuitive and powerful Unity game engine is one of the most widely used and best loved packages for game development. Unity scripting is an essential but challenging skill to master in order to create custom game elements. Learning modular scripting allows you to rewrite as little code as possible as you deploy your scripts to multiple projects and work easier, quicker, and more efficiently than before. In each chapter of this book, you'll learn how to script new game elements. Beginning with making custom controls for the keyboard and mouse, as well as the Xbox 360 Controller, you'll then get to grips with more complex systems such as inventory, data saving, and artificial intelligence. As you create these elements, you'll also learn how to make your scripts simpler and easy to use. This will allow drag-and-drop deployment, which is to be used by designers and nonprogrammers. Finally, you'll combine all of your newfound skills to create your own complete game project.
Table of Contents (12 chapters)
11
Index

Chapter 6. Keeping Score

In many games, having stats and scores are a way of showing the players how far along they've come. For some games, stats decide whether players win or lose the game or rounds they play. There are some games where stats create competition such as a high score table in a racing game, or a ranking system in a first-person shooter game. Stats can be used in many ways. They can influence a player to do things they normally wouldn't do, just to get that stat.

In this chapter, we will:

  • Create stats for the player
  • Implement those stats in our scripts
  • Create a stat tracker for the stats
  • Create an achievement system
  • Use PlayerPrefs to save our stats
  • Use GUI methods to show the stats and achievements
  • Create/assign the stats

Before we implement our stats, we need to figure out what stats we want to keep track of. This is a rudimentary yet an important step.