Beispiel #1
0
    void OnTriggerEnter2D(Collider2D hitInfo)
    {
        PlayerHealth player = hitInfo.GetComponent <PlayerHealth>();

        if (player != null)
        {
            player.TakeDamage(damage);      // damage player
        }

        Enemy enemy = hitInfo.GetComponent <Enemy>();

        if (enemy != null)
        {
            SoundManagerScript.PlaySound("bulletImpact");
            enemy.TakeDamage(damage);       // damage enemy
        }

        BarrelExplode barrel = hitInfo.GetComponent <BarrelExplode>();

        if (barrel != null)
        {
            barrel.TakeDamage(1);
        }

        Destroy(gameObject);
        GameObject bulletImpact = Instantiate(impactEffect, transform.position, transform.rotation);

        Destroy(bulletImpact, 0.4f);
    }
Beispiel #2
0
    void OnTriggerEnter2D(Collider2D col)
    {
        // kills player when fallen into lava
        if (col.name == "Player")
        {
            PlayerHealth playerHealth = col.GetComponent <PlayerHealth>();
            playerHealth.TakeDamage(100);

            FindObjectOfType <GameManager>().EndGame();

            // disables player sliding due to no friction
            Rigidbody2D player = col.GetComponent <Rigidbody2D>();
            player.velocity = new Vector2(0f, 0f);
        }

        // kills enemy when fallen into lava
        if (col.tag == "Enemy")
        {
            Enemy enemy = col.GetComponent <Enemy>();
            enemy.TakeDamage(500);
        }

        // explodes barrel when fallen into lava
        if (col.tag == "Barrel")
        {
            BarrelExplode barrel = col.GetComponent <BarrelExplode>();
            barrel.TakeDamage(2);
        }
    }
Beispiel #3
0
    void OnTriggerEnter2D(Collider2D hitInfo)
    {
        Enemy enemy = hitInfo.GetComponent <Enemy>();

        if (enemy != null)
        {
            enemy.TakeDamage(damage);
        }

        BarrelExplode barrel = hitInfo.GetComponent <BarrelExplode>();

        if (barrel != null)
        {
            barrel.TakeDamage(1);
        }

        // sword knockback
        if (hitInfo.tag == "Barrel" || hitInfo.tag == "Enemy")
        {
            Rigidbody2D prop = hitInfo.gameObject.GetComponent <Rigidbody2D>();
            if (PlayerMovement.facingRight)
            {
                prop.AddForce(new Vector2(knockbackX, knockbackY), ForceMode2D.Impulse);
            }
            else
            {
                prop.AddForce(new Vector2(-knockbackX, knockbackY), ForceMode2D.Impulse);
            }
        }
    }
Beispiel #4
0
    void OnTriggerEnter2D(Collider2D hitInfo)
    {
        Enemy enemy = hitInfo.GetComponent <Enemy>();

        if (enemy != null)
        {
            enemy.TakeDamage(enemyMaxDamage);       // damage enemy
        }

        BarrelExplode barrel = hitInfo.GetComponent <BarrelExplode>();

        if (barrel != null)
        {
            barrel.TakeDamage(2);
        }

        PlayerHealth player = hitInfo.GetComponent <PlayerHealth>();

        if (player != null)
        {
            player.TakeDamage(playerMaxDamage);     // damage player
        }
    }