Esempio n. 1
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        ProjectileController projectile = collision.gameObject.GetComponent <ProjectileController> ();

        if (projectile && projectile.gameObject.tag == "Projectile")
        {
            health -= projectile.projectileDamage;
            projectile.Hit(health, gameObject);
        }
        // the impulse is taken from health for damage
        if (collision.gameObject.tag == "Projectile" ||
            collision.gameObject.tag == "Vessel" ||
            collision.gameObject.tag == "Scenery")
        {
            health -= collision.relativeVelocity.magnitude * collision.gameObject.GetComponent <Rigidbody2D>().mass / 20;
        }

        if (health <= 0f)
        {
            Die();
        }

        if (collision.gameObject.tag == "CivWp")
        {
            Destroy(collision.gameObject);
        }
    }
    void OnTriggerEnter2D(Collider2D collider)
    {
        ProjectileController missile = collider.gameObject.GetComponent <ProjectileController>();

        if (missile)
        {
            missile.Hit();
            health -= missile.GetDamage();
            if (health <= 0)
            {
                Death();
            }
            Debug.Log("Hit by a missile");
        }
    }