Preparing the Coin Box Prefabs

We need coin boxes that our coins can pop out of. These are going to be slightly more complicated Prefabs than we’ve done thus far, involving several nested GameObjects. After being struck, our coin boxes will visually change to inform the player that the box is now empty.

First, we’ll create the active coin box Prefab by taking the following steps:

1. Create an empty GameObject and name it “boxCoin_active.”

2. Add a Sprite Renderer Component to it and select tiles_spritesheet_122.

3. Add a Box Collider 2D Component to the GameObject.

4. Add a second Box Collider 2D Component and mark it as a trigger.

5. Use the Add Component button to create a new script named “CoinBox,” then drag the script to our _scripts folder. ...

Get Learning 2D Game Development with Unity®: A Hands-On Guide to Game Creation now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.