protected new void OnCollisionEnter2D(Collision2D coll)
    {
        bool destroy = true;

        if (coll.gameObject.tag == "Player")
        {
            PlayerController pc = coll.gameObject.GetComponent <PlayerController>();
            if (source == pc.type)
            {
                destroy = false;
            }
            else
            {
                pc.AddDamage(damage);
            }
        }

        if (coll.gameObject.tag == "Enemy")
        {
            IEnemy ei = coll.gameObject.GetComponent <IEnemy>();
            if (source != ei.type)
            {
                ei.AddDamage(damage);
            }
            else
            {
                destroy = false;
            }
        }
        if (coll.gameObject.tag == "Projectile")
        {
            destroy = false;
        }

        if (destroy)
        {
            bc.enabled           = false;
            transform.localScale = new Vector3(transform.localScale.x * 2, transform.localScale.y * 2, transform.localScale.z);
            anim.SetBool("hit", true);
            rb2d.velocity = new Vector2(0, 0);
        }
    }
Esempio n. 2
0
    protected void OnCollisionEnter2D(Collision2D coll)
    {
        bool destroy = true;

        if (coll.gameObject.tag == "Player")
        {
            PlayerController pc = coll.gameObject.GetComponent <PlayerController>();
            if (source == pc.type)
            {
                destroy = false;
            }
            else
            {
                pc.AddDamage(damage);
            }
        }

        if (coll.gameObject.tag == "Enemy")
        {
            IEnemy ei = coll.gameObject.GetComponent <IEnemy>();
            if (source != ei.type)
            {
                ei.AddDamage(damage);
            }
            else
            {
                destroy = false;
            }
        }
        if (coll.gameObject.tag == "Projectile")
        {
            destroy = false;
        }

        if (destroy)
        {
            Destroy(transform.gameObject);
        }
    }