// Update is called once per frame void Update() { if (knockedDown == true && tookDamage == false) //if enemy is knocked down set animator boolean knocked down to true and start knocked down coroutine { stats.displayUI = true; healthUI = GameObject.FindGameObjectWithTag("EnemyHealthUI"); animator.SetBool("Knocked Down", true); StartCoroutine(KnockedDown()); } else if (tookDamage == true) //if enemy is taking damage set is hit to true and start took damage coroutine { stats.displayUI = true; healthUI = GameObject.FindGameObjectWithTag("EnemyHealthUI"); animator.SetBool("Is Hit", true); StartCoroutine(TookDamage()); } else if (tookDamage == false && //if enemy is in attack distance, stop enemy movement and start attack enemySight.playerInSight == true && enemySight.player.GetComponent <WarriorControllerScript>().knockedDown == false && enemySight.targetDistance < enemyAttack.attackRange && navMeshAgent.velocity.sqrMagnitude < enemyAttack.attackStartDelay) { stats.displayUI = false; healthUI = null; animator.SetBool("Attack", true); animator.SetBool("Run", false); } else if (knockedDown == false && //if player is in sight of enemy, move enemy towards player tookDamage == false && enemySight.playerInSight == true) { stats.displayUI = false; healthUI = null; animator.SetBool("Attack", false); animator.SetBool("Run", true); } else if (tookDamage == false && enemySight.playerInSight == false) //if player is not inside enemy's field of view, enemy stays idle { stats.displayUI = false; healthUI = null; animator.SetBool("Run", false); animator.SetBool("Attack", false); } if (currentAnimState == idleState) //set enum to enemy state { currentState = currentStateEnum.idle; } else if (currentAnimState == runState) { currentState = currentStateEnum.run; } else if (currentAnimState == attackState) { currentState = currentStateEnum.attack; } currentStateInfo = animator.GetCurrentAnimatorStateInfo(0); //determine which animation is currently executing currentAnimState = currentStateInfo.fullPathHash; }
private void Update() { // get knocked down if (knockedDown && !tookDamage) { animator.SetBool("Knocked Down", true); StartCoroutine(KnockedDown()); } // take damage else if (tookDamage && !knockedDown) { if (enemyState.health <= 0) { animator.SetBool("Knocked Down", true); StartCoroutine(KnockedDown()); } else { animator.SetBool("Is Hit", true); StartCoroutine(TookDamage()); } } // attack logic else if (!tookDamage && EnemySight.playerInSight && !LeonardoFall.knockedDown && EnemySight.targetDistance < EnemyAttack.attackRange && navMeshAgent.velocity.sqrMagnitude < EnemyAttack.attackStartDelay) { animator.SetBool("Attack", true); animator.SetBool("Walk", false); } // walk to player else if (!knockedDown && !tookDamage && EnemySight.playerInSight && !LeonardoFall.knockedDown) { animator.SetBool("Walk", true); animator.SetBool("Attack", false); } //idle else if (!tookDamage && !EnemySight.playerInSight || LeonardoFall.knockedDown) { animator.SetBool("Walk", false); animator.SetBool("Attack", false); } if (currentAnimState == idleState) { currentState = currentStateEnum.idle; } else if (currentAnimState == walkState) { currentState = currentStateEnum.walk; } if (currentAnimState == attack1State) { currentState = currentStateEnum.attack; } if (currentAnimState == hurtState) { currentState = currentStateEnum.hurt; } currentStateInfo = animator.GetCurrentAnimatorStateInfo(0); currentAnimState = currentStateInfo.fullPathHash; }