void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Player"))
        {
            shake.CamShake();

            Instantiate(effect, transform.position, Quaternion.identity);
            other.GetComponent <player>().currentHealth -= damage;
            Destroy(gameObject);
        }

        if (other.CompareTag("Enemy"))
        {
            shake.CamShake();
            Instantiate(effect, transform.position, Quaternion.identity);

            Destroy(gameObject);
        }
    }
Exemplo n.º 2
0
    //----------------------------------------------------------
    void OnCollisionEnter2D(Collision2D col)
    {
        if (col.gameObject.tag == tag)
        {
            scoreGoodCollected++;
            audioSource.PlayOneShot(getGoodPoint, 1);
        }
        else if (col.gameObject.tag == "Obstaculo")
        {
            audioSource.PlayOneShot(hit, 2);
            shake.CamShake();
            hp--;
        }
        else
        {
            scoreWrongCollected++;
            audioSource.PlayOneShot(getBadPoint, 1);
        }

        scoreGoodText.text  = "Reciclables: " + scoreGoodCollected.ToString();
        scoreWrongText.text = "No Reciclables: " + scoreWrongCollected.ToString();
        Destroy(col.gameObject);
    }