Beispiel #1
0
    void OnTriggerStay2D(Collider2D other)
    {
        if (enable)
        {
            RubyController controller = other.GetComponent <RubyController>();

            if (controller != null)
            {
                controller.ChangeHealth(-1);
            }

            Hostage hostage = other.GetComponent <Hostage>();

            if (hostage != null)
            {
                hostage.ChangeHealth(-1);
            }
        }
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        bool           hit = false;
        RubyController t   = collision.GetComponent <RubyController>();

        if (t != null)
        {
            t.ChangeHealth(-1);
            hit = true;
        }

        Hostage h = collision.GetComponent <Hostage>();

        if (h != null)
        {
            h.ChangeHealth(-1);
            hit = true;
        }
        if (hit)
        {
            Destroy(gameObject);
        }
    }