// ----- Inflict Splash Damage ----- /* * Creates a game object, defined by the prefab parameter 'splashDamageCirclePrefab', centered around the 'enemyUnit'. * This prefab contains a SplashDamageCircle script, so this game object can be cast to a SplashDamageCircle. * This SplashDamageCircle is such that any enemy unit that touches it will take Mathf.Floor('damage' / 2) damage. * This game object is destroyed after a short time interval. */ private void InflictSplashDamage(EnemyUnit enemyUnit, float damage, Transform splashDamageCirclePrefab) { SplashDamageCircle splashCircle = Instantiate(splashDamageCirclePrefab, enemyUnit.transform).GetComponent <SplashDamageCircle>(); splashCircle.damage = Mathf.Floor(damage / 2); splashCircle.projectile = this; StartCoroutine(SplashCooldownTime(SPLASH_CIRCLE_APPEARANCE_TIME, splashCircle)); }
private IEnumerator SplashCooldownTime(float time, SplashDamageCircle splashCircle) { yield return(new WaitForSeconds(time)); if (splashCircle != null) { Destroy(splashCircle.gameObject); } Destroy(this.gameObject, 0.1f); // Race condition - remove splash circle first }