0 points

Explosion Damage (Radius);


dashboard

Thu Dec 03 2020 15:29:16 GMT+0000 (UTC)

Posted by @Sarvar #c# #explosion #damage #radius #unity

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);
            }
        }
    }
}
content_copy Copy

Agar siz Radius boyicha tasir qiluvchi zarba berishni xoxlasangiz ushbu Code - dan foydalaning