Preparing the Floating Coin Prefabs for Collection

We’re going to need a trigger in order to detect when the player comes into contact with the coin. Rather than make a trigger that’s the size of the coin itself, we should consider making it a bit larger. From how far away do we want the player to be able to collect these coins? The wider the trigger, the easier it will be for them to do so, though it may look strange if we make it so large that the player collects the coin without appearing to touch it. Let’s try the following for each of the coin Prefabs:

1. Select the coin Prefab.

2. Click the Add Component button and select Physics 2D > Circle Collider 2D.

3. Click the “Is Trigger” property to set it to true.

4. Set the “Radius” property ...

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.