Exemplo n.º 1
0
    private IEnumerator PickupCoin(Collision2D coll)
    {
        gameObject.GetComponent <SpriteRenderer>().enabled = false;
        gameObject.GetComponent <Collider2D>().enabled     = false;

        // Manage score
        if (coll.collider.tag.Contains("SX"))
        {
            int value = Convert.ToInt32(playerOneScoreBox.GetComponent <Text>().text);
            if (gameObject.tag.Contains("SX"))
            {
                value++;
                playerOne.IncreaseScore();
                // Play sound
                audioPlayer.PlayOneShot(positiveCoinClip);
            }
            else
            {
                value--;
                playerOne.DecreaseScore();
                // Play sound
                audioPlayer.PlayOneShot(negativeCoinClip);
            }
            playerOneScoreBox.GetComponent <Text>().text = value + "";
        }
        else if (coll.collider.tag.Contains("DX"))
        {
            int value = Convert.ToInt32(playerTwoScoreBox.GetComponent <Text>().text);
            if (gameObject.tag.Contains("DX"))
            {
                value++;
                playerTwo.IncreaseScore();
                // Play sound
                audioPlayer.PlayOneShot(positiveCoinClip);
            }
            else
            {
                value--;
                playerTwo.DecreaseScore();
                // Play sound
                audioPlayer.PlayOneShot(negativeCoinClip);
            }
            playerTwoScoreBox.GetComponent <Text>().text = value + "";
        }

        yield return(new WaitForSeconds(1.8f));

        if (gameObject.tag.Contains("SX"))
        {
            assetsPool.FreeObjectPool(eObjectType.COIN_SX, gameObject);
        }
        else if (gameObject.tag.Contains("DX"))
        {
            assetsPool.FreeObjectPool(eObjectType.COIN_DX, gameObject);
        }
    }
    private IEnumerator ExplosionParticlesEffect(Vector2 hitPoint)
    {
        GameObject effect = null;

        if (assetsPool && assetsPool.GetFreeObjectFromPool(eObjectType.EXPLOSION, out effect))
        {
            effect.transform.position = hitPoint;
            effect.transform.rotation = Quaternion.identity;
            effect.GetComponent <ParticleSystem>().Play();

            // Play sound
            audioPlayer.PlayOneShot(explosionClip);

            yield return(new WaitForSeconds(explosionTime));

            assetsPool.FreeObjectPool(eObjectType.EXPLOSION, effect);
        }

        yield return(null);
    }