private void Attack(StateController controller) { RaycastHit hit; Debug.DrawRay(controller.eyes.position, controller.eyes.forward.normalized * controller.Pnj.attackRange, Color.red); //NPC vise le joueur (change sa rotation par rapport au joueur) controller.transform.LookAt(controller.chaseTarget); if (controller.Pnj.Type == PnjStats.Npc_Type.Melee) { controller.navMeshAgent.isStopped = true; } else { if (Physics.SphereCast(controller.eyes.position, controller.Pnj.lookSphereCastRadius, controller.eyes.forward, out hit, controller.Pnj.attackRange) && hit.collider.CompareTag("Player")) { //vérifier si le joueur est dans le champs de vision de l'NPC if (controller.CheckIfCountDownElapsed(controller.CurrentAttackRate)) { controller.Shooting(); //Activer le son et réinitialiser le temps du prochaine attack controller.stateTimeElapsed = 0; } } } }
private void Patrol(StateController controller) { controller.navMeshAgent.destination = controller.wayPointList[controller.nextWayPoint].position; controller.navMeshAgent.isStopped = false; if (controller.navMeshAgent.remainingDistance <= controller.navMeshAgent.stoppingDistance && !controller.navMeshAgent.pathPending) { controller.anim.SetBool("Walking", false); //rester dans chaque Waypoints une durée de 5s if (controller.CheckIfCountDownElapsed(5)) { controller.anim.SetBool("Walking", true); controller.stateTimeElapsed = 0; controller.nextWayPoint = (controller.nextWayPoint + 1) % controller.wayPointList.Count; //changer vers le prochain Waypoint } } else { controller.anim.SetBool("Walking", true); } }