Exemple #1
0
    private void PickupCoin()
    {
        GameSession gameSession = FindObjectOfType <GameSession>();

        if (wasCollected)
        {
            return;
        }
        if (coinSound != null)
        {
            GameObject audioListener = GameObject.FindWithTag("AudioListener");
            AudioSource.PlayClipAtPoint(coinSound, audioListener.transform.position, coinVolume);
        }
        gameSession.AddCoins(coinValue);
        wasCollected = true;
        Destroy(gameObject);
    }
Exemple #2
0
    private void OnTriggerEnter2D(Collider2D otherCollider)
    {
        if (otherCollider.GetComponent <Player>() && isTimerUp)
        {
            Destroy(gameObject);

            audioManager.ClipPlayAtPoint(Camera.main.transform.position, 0.0f, this.coinPickupSound);

            if (!isGameSessionFound)
            {
                gameSession = FindObjectOfType <GameSession>();

                isGameSessionFound = true;
            }

            gameSession.AddCoins(coinValue);

            StartCoroutine(DelayCoinPickup());
        }
    }