- Home /
How to make collectibles
How do I make collectibles like coins that I can pick up. the number of coins should add to my score
Answer by Statement · Dec 22, 2013 at 12:39 PM
A simple solution is to add a collider to your coins and enable "Is Trigger".
Then you can respond to events where you pick up your coins.
// Example script that could be attached to the Player
// Example requires coins to be tagged "Coin" for this to work.
public int score;
void OnTriggerEnter(Collider other)
{
if (other.tag == "Coin")
{
score += 10;
Destroy(other.gameObject); // Or whatever way you want to remove the coin.
}
}
Two videos regarding colliders and triggers:
You can also invert the responibility, making the coin give the player score and destroy itself. It may make more sense, especially if you are going to have multiple kinds of coins.
Answer by zerotech15 · Apr 29, 2016 at 05:41 AM
Well, if you are looking for a ready solution you might like this one
Collect Me 8 - https://www.assetstore.unity3d.com/en/#!/content/59501
Your answer
![](https://koobas.hobune.stream/wayback/20220613124650im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Coins Multiplier 0 Answers
How would I go about removing a mesh renderer component on collision with a trigger? 1 Answer
Audio Clip constantly play 1 Answer
Mission Objectives 1 Answer