Beispiel #1
0
    private void DestroyObject()
    {
        if (totalArmor <= 0)
        {
            switch (parent)
            {
            case Parent.Rocket: {
                RocketScript rocket = gameObject.GetComponent <RocketScript>();
                if (rocket != null && rocket.allowTriggers)
                {
                    rocket.CustomDestroy();
                }
            } break;

            case Parent.Asteroid: {
                Asteroid asteroid = gameObject.GetComponent <Asteroid>();
                if (asteroid != null)
                {
                    asteroid.CustomDestroy();
                }
            } break;

            case Parent.Ship: {
                ShipScript ship = gameObject.GetComponent <ShipScript>();
                if (ship != null)
                {
                    ship.CustomDestroy();
                }
            } break;
            }
        }
    }
Beispiel #2
0
    void OnTriggerEnter2D(Collider2D otherCollider)
    {
        if (otherCollider.GetType() == typeof(BoxCollider2D))
        {
            // Is this a rocket shot?
            RocketScript rocketShot = otherCollider.gameObject.GetComponent <RocketScript>();
            if (rocketShot != null)
            {
                if (rocketShot.allowTriggers)
                {
                    TakeDamage(rocketShot.parentGuid);
                    Damage(rocketShot.damage, rocketShot.damageType, rocketShot.turretSize);
                    rocketShot.CustomDestroy();
                }
            }

            // Is this a gun shot?
            BulletScript bulletShot = otherCollider.gameObject.GetComponent <BulletScript>();
            if (bulletShot != null)
            {
                if (bulletShot.allowTriggers)
                {
                    TakeDamage(bulletShot.parentGuid);
                    Damage(bulletShot.damage, bulletShot.damageType, bulletShot.turretSize);
                    bulletShot.CustomDestroy();
                }
            }

            // Is this a asteroid collision?
            Asteroid asteroid = otherCollider.gameObject.GetComponent <Asteroid>();
            if (asteroid != null)
            {
                Damage(asteroid.damage);
            }

            // Is this a player collision?
            ShipScript ship = otherCollider.gameObject.GetComponent <ShipScript>();
            if (ship != null)
            {
                //Damage(10);
            }
        }
    }