// Update is called once per frame private void FixedUpdate() { //raycast field of view old //RaycastHit2D fovInfo = Physics2D.Raycast(FOV.position, FOV.right); if (enemyAi.getFacingRight()) { aimDir = new Vector3(1, 1f, 0f); } else if (!enemyAi.getFacingRight()) { aimDir = new Vector3(-1, 1f, 0f); } fieldOfView.SetOrigin(FovStartPoint.position); fieldOfView.SetAimDirection(aimDir); if (FindTargetPlayer()) { //enemyAi.setSpeed(2f); GetComponentInParent <EnemyAi>().enabled = true; //if raycast hit player (enemy sees player) if (enemyAi.reachedPlayer()) { //reached player so attack with timeout if (Time.time >= nextAttackTime) { GetComponent <SkeletonGFXCombat>().Attack(); //atack + anim enemyAi.setCanMove(0); nextAttackTime = Time.time + 1f / attackRate; //audio of attacking audioManager.Play("AxeSwoosh1"); audioManager.Play("AxeHitMetal_1", 0.2f); } } else { //didn't reach player, so move towards player if (animator.GetCurrentAnimatorStateInfo(0).normalizedTime > 0.8f && !animator.IsInTransition(0)) // if attack anim finished { enemyAi.setCanMove(1); } if (enemyAi.getIsMoving()) // if enemy moving { animator.SetTrigger("Go_To_Walk"); } } } else { if (!this.animator.GetCurrentAnimatorStateInfo(0).IsName("Skeleton_Attack")) // if attack anim finished { enemyAi.setCanMove(2); } if (enemyAi.getIsMoving()) // if enemy moving { animator.SetTrigger("Go_To_Walk"); } else { animator.SetTrigger("Go_To_Idle"); } } }