//---------------------------------------------------------------------------------------------- // Reason() is used to determine the conditions to transition out of the melee attack state, // and what state to transition into public override void Reason() { Transform adolescentTransform = npcAdolescentController.transform; Vector3 closestplayer = npcAdolescentController.GetClosestPlayer(); if (health && health.IsDead()) { //if the health script is present on the adolescent and its dead, transition to the dead //state npcAdolescentController.PerformTransition(Transition.NoHealth); return; } bool playersDead = true; for (int i = 0; i < GameManager.instance.Players.Count; i++) { if (playerHealths[i] && !playerHealths[i].IsDead()) { playersDead = false; break; } } if (playersDead) { npcAdolescentController.PerformTransition(Transition.PlayerDead); return; } if ((health && health.CurrentHealth <= 10) || GameManager.instance.AdolescentCount == 1) { npcAdolescentController.PerformTransition(Transition.InDanger); return; } if (IsInCurrentRange(adolescentTransform, closestplayer, NPCAdolescentController.ATTACK_DIST)) { adolescentAttack.Attacking = true; } else if (IsInCurrentRange(adolescentTransform, closestplayer, NPCAdolescentController.CHASE_DIST)) { //if the player's distance is in range of the chase distance, stop firing and chase //the player adolescentAttack.Attacking = false; npcAdolescentController.PerformTransition(Transition.SawPlayer); } else { adolescentAttack.Attacking = false; npcAdolescentController.PerformTransition(Transition.LostPlayer); } }
//---------------------------------------------------------------------------------------------- // EnterStateInit() is used to initialize the adolescent when they enter the charge state public override void EnterStateInit() { // get a slot position Vector3 closestplayer = npcAdolescentController.GetClosestPlayer(); closestPlayerSlots = npcAdolescentController.GetPlayerSlotManager(npcAdolescentController.PlayerTarget); closestPlayerSlots.ClearSlots(npcAdolescentController.gameObject); availSlotIndex = closestPlayerSlots.ReserveSlotAroundObject(npcAdolescentController.gameObject); if (availSlotIndex != -1) { // if the available slot index isn't a non-existent number, assign it to the destPos destPos = closestPlayerSlots.GetSlotPosition(availSlotIndex); } else { //otherwise, assign the destPos to be the player's position destPos = closestplayer; } elapsedTime = 0.0f; }
//---------------------------------------------------------------------------------------------- // Reason() is used to determine the conditions to transition out of the idle state, // and what state to transition into public override void Reason() { Transform adolescentTransform = npcAdolescentController.transform; Vector3 closestplayer = npcAdolescentController.GetClosestPlayer(); if (health && health.IsDead()) { npcAdolescentController.PerformTransition(Transition.NoHealth); } if (IsInCurrentRange(adolescentTransform, closestplayer, NPCAdolescentController.FLEE_DIST)) { if ((health && health.CurrentHealth <= 10) || GameManager.instance.AdolescentCount == 1) { npcAdolescentController.PerformTransition(Transition.InDanger); return; } } if (IsInCurrentRange(adolescentTransform, closestplayer, NPCAdolescentController.CHASE_DIST)) { npcAdolescentController.PerformTransition(Transition.SawPlayer); return; } }