The coin prefab
To make things a little easier, I have already prepared the visual part of our coin. Download Coin.unitypackage
and import it into your project:
Great job! Now we drag the
Coin prefab into the Hierarchy view so that we can take a look at it. As mentioned before, I prepared this prefab visually. I have added Sprite
Renderer
to the game object and linked it with the coin sprite. I have also created a simple spin animation controlled by the Animator. Don't worry about it right now.
Now, you have to pick up from where I finished. Most collectables react with the environment through the physics of the game. We can use the 2D trigger here to react with the Player
Game Object Rigidbody2D
component. This is the exactly the same way we inserted LeaveTriggers
into the game previously.
Select the coin and add the CircleCollider2D
component. A green circle will appear around the coin, representing the triggering area. Make sure you tweak the radius value to roughly match the size...