//This selects one of the five available attacks the boss can perform. IEnumerator ChooseAttack(float waitTimer) { SetAnimationInteger("SkeletonKingCondition", idleAnimation); Debug.Log("Attack waiting"); choosingAttack = true; //While we wait for the boss attack to be chosen, the boss can be damaged, and this is done here. HealthScript.SetInvulnerable(false); isInvulnerableObject.SetActive(false); isAttackableObject.SetActive(true); yield return(new WaitForSeconds(waitTimer)); //Once we have chosen an attack, and are either performing it, or moving to it, we no longer can be damaged. HealthScript.SetInvulnerable(true); isInvulnerableObject.SetActive(true); isAttackableObject.SetActive(false); choosingAttack = false; //Choose an attack, update the state machine, call the correct functions int randNum = Random.Range(1, 6); Debug.Log(randNum); Debug.Log("CHose an attack"); //Where we choose the actions the attack, and what functions to perform. switch (randNum) { case 1: currentState = States.Attack1Ground; ChooseAPlayer(); Moveto(chosenPlayerPosition, true); break; case 2: currentState = States.Attack2Adds; //This state bypasses having to call functions in update StartCoroutine(Attack2(3.0f)); break; case 3: currentState = States.Attack3SkySword; //This state also bypasses having to call functions in update StartCoroutine(Attack3(3.0f)); break; case 4: currentState = States.Attack4Rotate; ChooseAPlayer(); Moveto(chosenPlayerPosition, true); break; case 5: currentState = States.Attack5Hand; StartCoroutine(Attack5(3.0f)); //This state as well as the other two bypasses having to call update functions break; } }