if (isExplosion) { foreach (GameObject enemy in units) { float distanceToEnemy = Vector3.Distance (transform.position, enemy.transform.position); if (distanceToEnemy <= explosionRadius) { Unit unit = enemy.GetComponent<Unit> (); float proximity = (transform.position - enemy.transform.position).magnitude; float effect = 1 - (proximity / explosionRadius); unit.TakeDamage ((int) (damage * effect)); if (enemy.GetComponent<Setup> ().currentHealth <= 0) { GameObject explosionDestroy = Instantiate (enemy.GetComponent<Setup> ().explosionDestroy, enemy.transform.position, Quaternion.identity); Destroy (explosionDestroy, 1); Destroy (enemy); } } } }