void CheckForEnemiesInRadius() { int hits = 0; Collider[] objectsInRange = Physics.OverlapSphere(transform.position, damageRadius); foreach (Collider col in objectsInRange) { if (col.gameObject.tag == "Structure") { StructureController structure = col.gameObject.GetComponent <StructureController>(); if (structure != null) { structure.TakeDamage(damage); } } else if (col.gameObject.tag == "Turret") { } else if (col.gameObject.tag == "Enemy") { EnemyBulletController enemy = col.GetComponent <EnemyBulletController>(); if (enemy != null) { float proximity = (transform.position - enemy.transform.position).magnitude; float effect = 1 - (proximity / damageRadius); float damageAmount = (damage * effect); damageAmount = Mathf.Clamp(damageAmount, 1.0f, damage); enemy.DealDamage(damage); hits++; } } } if (hits > 0) { ExpireMe(); } }
void CheckForEnemiesInRadius() { Collider[] objectsInRange = Physics.OverlapSphere(transform.position, controller.damageRadius); float damage = controller.damage; foreach (Collider col in objectsInRange) { if (col.gameObject.tag == "Structure") { StructureController structure = col.gameObject.GetComponent <StructureController>(); Debug.DrawLine(transform.position, col.gameObject.transform.position, Color.red, 2.0f); if (structure != null) { float proximity = (transform.position - structure.transform.position).magnitude; float effect = 1 - (proximity / controller.damageRadius); float damageAmount = (damage * effect); damageAmount = Mathf.Clamp(damageAmount, 1.0f, damage); structure.TakeDamage(damageAmount); } } else if (col.gameObject.tag == "Turret") { TurretBarrelController turret = col.gameObject.GetComponent <TurretBarrelController>(); Debug.DrawLine(transform.position, col.gameObject.transform.position, Color.red, 2.0f); if (turret != null) { float proximity = (transform.position - turret.transform.position).magnitude; float effect = 1 - (proximity / controller.damageRadius); float damageAmount = (damage * effect); damageAmount = Mathf.Clamp(damageAmount, 1.0f, damage); turret.TakeDamage(damageAmount); } } } }