Skip to Main Content
Learning 2D Game Development with Unity®: A Hands-On Guide to Game Creation
book

Learning 2D Game Development with Unity®: A Hands-On Guide to Game Creation

by Matthew Johnson, James A. Henley
December 2014
Beginner content levelBeginner
384 pages
11h 15m
English
Addison-Wesley Professional
Content preview from Learning 2D Game Development with Unity®: A Hands-On Guide to Game Creation

Creating the Scripts

Next, we will need to create a few scripts to hook the player up to the HUD elements, so when we take damage or collect coins in the level, they will update accordingly.

Let’s first add a script to the hud_sprite display so that we can add to the total when we collect coins. This will be slightly different from anything we have learned yet, as we are counting up but displaying the results using sprites.

1. Create a new script and call it “CoinCounter.” Place it inside the GUI folder of our _scripts folder, just for organizational reasons.

2. With the script selected, drag it and attach it to the hud_sprite element in the Scene or Hierarchy.

3. Double-click to open it and adjust the contents to match Listing 10.5.

Listing ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Game Development with MonoGame: Build a 2D Game Using Your Own Reusable and Performant Game Engine

Game Development with MonoGame: Build a 2D Game Using Your Own Reusable and Performant Game Engine

Louis Salin, Rami Morrar
Game Development Projects with Unreal Engine

Game Development Projects with Unreal Engine

Hammad Fozi, Gonçalo Marques, David Pereira, Devin Sherry

Publisher Resources

ISBN: 9780133523416Purchase book