Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

How to collect coin in Unity?

Discussion in 'Scripting' started by huseyinbaba58, Aug 10, 2020.

  1. huseyinbaba58

    huseyinbaba58

    Joined:
    Feb 12, 2020
    Posts:
    146
    I researched more sources but I can't find.How can I do it?
     
  2. Dextozz

    Dextozz

    Joined:
    Apr 8, 2018
    Posts:
    488


    Where did you actually search? This is is the first result on youtube.
     
    huseyinbaba58 likes this.
  3. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    I asked a good friend of mine. He says he only knows ~ 3 millions things related to "collect coins unity". I'm afraid we're stuck in the same situation and I can't help you, but I tried my best. Sorry.

    This post may contain traces of sarcasm.
     
    Last edited: Aug 10, 2020
    Dextozz likes this.
  4. huseyinbaba58

    huseyinbaba58

    Joined:
    Feb 12, 2020
    Posts:
    146
    I watched it but that is so ambigous.
     
  5. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,724
    A lot like your original question then.
     
  6. VladimirTa

    VladimirTa

    Joined:
    Jul 17, 2013
    Posts:
    40
    One of the ways is to add a trigger collider to the coin and to the character that will be collecting it.
    One of the objects also must contain a Rigidbody.
    Add some tag like "CoinToCollect" to the coin.
    Then add a script to the character that will be collecting the coins.
    Finally, in the OnTriggerEnter() add to check if the tag is CoinToCollect to collect only objects that should be collected.
    After that, you can do all sorts of cool stuff you want with the coin.

    For example:
    Code (CSharp):
    1. private void OnTriggerEnter(Collider collider)
    2.     {
    3.         if (collider.tag == "CoinToCollect")
    4.         {
    5.             // Here you can do all sorts of cool stuff with the collected coin.
    6.             // Like rotate it, activate particles, play audio, or just destroy it.
    7.  
    8.             // Destroys collected coin.
    9.             Destroy(collider.gameObject);
    10.         }
    11.     }
     
  7. huseyinbaba58

    huseyinbaba58

    Joined:
    Feb 12, 2020
    Posts:
    146
    I was late so thanks dudes.