Double coin pickup

I used the code from the course, but it is still 200 points for a coin.

private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.tag == "Player" && (!wasCollected))
        {
            wasCollected = true;
            FindObjectOfType<GameSession>().AddToScore(scoreForCoin);
            AudioSource.PlayClipAtPoint(coinPickupSFX, Camera.main.transform.position);
            gameObject.SetActive(false);
            Destroy(gameObject);
           
        }
        
    }

Hi Super_Good,

Welcome to our community! :slight_smile:

First of all, please add a Debug.Log to the method. Also log GetInstanceID() into your console. This way, you will see if this piece of code was indeed collected twice.

And log the value of scoreForCoin into your console to ensure that it is indeed 100 and not 200.

Let me know what you figured out!

I found the reason. The CoinPickup script was added twice on the Coin object. Thank you!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms