Example #1
0
    void Explode()
    {
        Collider[] nearbyObjects = Physics.OverlapSphere(transform.position, blastRadius);
        foreach (Collider thing in nearbyObjects)
        {
            UnitControl enemyInRange = thing.GetComponent <UnitControl>();
            if (enemyInRange && !enemyInRange.IsDead())
            {
                if (Vector3.Distance(transform.position, enemyInRange.transform.position) < blastRadius * 0.25f)
                {
                    enemyInRange.Die(true);
                }
                else
                {
                    enemyInRange.Knockback(transform.position, damage);
                }
            }
        }
        GameObject effect = Instantiate(explosionEffect, transform.position, Quaternion.identity) as GameObject;

        effect.gameObject.AddComponent <ParticleKiller>();
        Destroy(gameObject);
    }