Example #1
0
    protected void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.GetComponent <Bullet>() != null)
        {
            //TODO: Make this to reduce damage using Bullet.damage attribute                DONE
            resistance -= collision.gameObject.GetComponent <Bullet>().Damage;

            if (resistance == 0)
            {
                OnHazardDestroyed();
            }

            Destroy(collision.gameObject);
            counter++;

            mText      = GameObject.Find("HazardCounter").GetComponent <Text>();
            mText.text = "Destroyed Hazards = " + counter;
        }

        if (collision.gameObject.GetComponent <APBullet>() != null)
        {
            //TODO: Make this to reduce damage using Bullet.damage attribute                DONE
            resistance -= collision.gameObject.GetComponent <APBullet>().Damage;

            if (resistance == 0)
            {
                OnHazardDestroyed();
            }
            counter++;

            mText.text = "Destroyed Hazards = " + counter;
        }

        if (collision.gameObject.GetComponent <Shelter>() != null)
        {
            Shelter shelter = collision.gameObject.GetComponent <Shelter>();

            shelter.Damage(1);
            OnHazardDestroyed();

            if (shelter.IsInvoking("Regenerate") == true)
            {
                shelter.CancelInvoke("Regenerate");
                shelter.Invoke("Regenerate", shelter.regenTime);
            }
            else
            {
                shelter.Invoke("Regenerate", shelter.regenTime);
            }
        }
    }