public override void OnEnemyStruck(GameObject player, GameObject enemy) { if (_player == null) { _player = player; } if (Random.Range(0, 6) <= 1) { SpecialsHolder holder = player.GetComponentInChildren <SpecialsHolder>(); holder.StartCoroutine(LaunchFireballs(holder, count)); } }
IEnumerator LaunchFireballs(SpecialsHolder holder, int fireball_amount) { for (var i = 0; i < fireball_amount; i++) { yield return(new WaitForSeconds(0.2f)); holder.PlayFireballSound(); GameObject fireball = GameObject.Instantiate(holder.Fireball, holder.transform.position, holder.transform.rotation); fireball.GetComponent <ProjectileBehavior>().shotFrom = this; Rigidbody2D rigidbody = fireball.GetComponent <Rigidbody2D>(); rigidbody.AddForce(new Vector2(Random.Range(-150.0f, 150.0f), Random.Range(120.0f, 150.0f))); holder.StartCoroutine(StopFireballAndSeekEnemy(rigidbody)); } }