示例#1
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        DamageDealer damageDealer = collision.gameObject.GetComponent <DamageDealer>();

        if (damageDealer && damageDealer.GetAttackPlayer())
        {
            healt -= damageDealer.GetDamage();
            if (healt <= 0)
            {
                audioSource.PlayOneShot(deathSound);
                healtText.text = "You died!";
                Destroy(gameObject);
                sceneLoader.LoadGameOver();
            }
            else
            {
                healtText.text = healt.ToString();
            }
            damageDealer.Hit();
        }
    }
示例#2
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        DamageDealer damageDealer = collision.gameObject.GetComponent <DamageDealer>();

        if (damageDealer && !damageDealer.GetAttackPlayer())
        {
            healt -= damageDealer.GetDamage();
            if (healt <= 0)
            {
                //Particle animation
                Destroy(gameObject);
                GameObject expolision = Instantiate(deathVFX, transform.position, transform.rotation);

                AudioSource.PlayClipAtPoint(deathSound, Camera.main.transform.position);
                gameSession.AddScore(score);

                Destroy(expolision, 1f);
            }
            damageDealer.Hit();
        }
    }