Exemple #1
0
    // Use this for initialization
    void Start()
    {
        Collider[] colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius);

        foreach (Collider otherCollider in colliders)
        {
            ExplodingElement explodingElement = otherCollider.gameObject.GetComponent <ExplodingElement>();

            if (explodingElement != null)
            {
                explodingElement.Explode(transform.position, m_ExplosionRadius, m_ExplosionForce);
            }

            BaseHealth <int> health = otherCollider.gameObject.GetComponent <BaseHealth <int> >();
            if (health != null)
            {
                health.Damage(m_Damage);
            }
        }

        m_Camera = Camera.main.GetComponent <CameraController>();
        if (m_Camera != null)
        {
            m_Camera.Shake(m_CameraShake);
        }
    }
Exemple #2
0
    public static void FallApartHelper(GameObject obj, GameObject effectPrefab, Vector3 pos, float radius, float force)
    {
        obj.AddComponent <TimedLife>();

        for (int i = 0; i < obj.transform.childCount; i++)
        {
            Transform child = obj.transform.GetChild(i);
            child.gameObject.AddComponent <Rigidbody>();
            child.gameObject.AddComponent <SphereCollider>();
            child.gameObject.AddComponent <TimedLife>();
            ExplodingElement element = child.gameObject.AddComponent <ExplodingElement>();
            if (effectPrefab != null)
            {
                element.m_CollisionEffectsPrefab = effectPrefab;
            }
            element.Explode(pos, radius, force);
            FallApartHelper(child.gameObject, effectPrefab, pos, radius, force);
        }
        obj.transform.DetachChildren();
    }