ai_state current_state = ai_state.idle; //instantiates the ai with an idle state. public IEnumerator Dodge() //this is the dodge of the AI, it will randomly choose left or right dodges. { alerted = false; //set alert to false to make the AI stop chasing the player to allow dodging. dodge = (dodge_direction)Random.Range(0, 2); //randomly picks a direction to dodge. 0 is left, 1 is right. yield return(new WaitForSeconds(dodge_time)); alerted = true; //set alert back to true to make the AI chase the player again. dodge = dodge_direction.not_dodging; yield return(new WaitForSeconds(cooldown_action)); performing_action = false; //the AI is done with the action }
protected IEnumerator Dodge() //this is the dodge of the AI, it will randomly choose left or right dodges. { alerted = false; //set alert to false to make the AI stop chasing the player to allow dodging. dodge = (dodge_direction)Random.Range(0, 2); //randomly picks a direction to dodge. 0 is left, 1 is right. if (dodge == dodge_direction.left) { animator.Play("LeftDodge"); } else if (dodge == dodge_direction.right) { animator.Play("RightDodge"); } cooldown_action = Random.Range(cooldown_action_min, cooldown_action_max); yield return(new WaitForSeconds(dodge_time)); alerted = true; //set alert back to true to make the AI chase the player again. dodge = dodge_direction.not_dodging; //reset the dodge's direction to no direction otherwise known as not_dodging. yield return(new WaitForSeconds(cooldown_action)); performing_action = false; //the AI is done with the action }