コード例 #1
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);
            }
        }
    }