IEnumerator RandomAttack()// Randomly move and crash in to the player { DoANewThing = false; float ran = Random.Range(moveDelay / 10, moveDelay); yield return(new WaitForSeconds(ran)); if (moveAbility == "fly") { //Debug.Log("LocalScale: " + transform.localScale); motor.StartSneak(); while (transform.localScale.x < 1.5f) { transform.localScale += new Vector3(0.25f, 0.25f, 0); enemyObj.alpha -= 0.25f; yield return(new WaitForSeconds(0.1f)); } } int moveAm = Random.Range(1, 5);//1,2,3,4 are the random moves GetAMove(moveAm); yield return(new WaitUntil(() => motor.hasTarget == false)); if (moveAbility == "fly") { motor.EndSneak(); while (transform.localScale.x > 1f) { transform.localScale -= new Vector3(0.25f, 0.25f, 0); enemyObj.alpha += 0.25f; yield return(new WaitForSeconds(0.1f)); } } float x = moveDelay - ran; yield return(new WaitForSeconds(x)); for (int i = 0; i < noOfShots; i++) { shooter.TargetPlayer(); yield return(new WaitForSeconds(targetDelay)); if (Vector2.Distance(transform.position, levelManager.playerBrain.transform.position) <= atkRange) { enemySpriteAnim.FlashRed(4); yield return(new WaitForSeconds(targetDelay)); FireGun(); yield return(new WaitForSeconds(atkSpeed)); } } yield return(new WaitUntil(() => shooter.shooting == false)); DoANewThing = true; yield return(null); }