/// <summary> /// Get current entities state /// </summary> /// <param name="cooldown">Current state cooldown. Range from 0 to 1</param> public States GetAIStatus(out float cooldown) { States result = States.Idle; float attentionCooldown, aggresionCooldown; attentionCooldown = aggresionCooldown = cooldown = 0; for (int i = 0; i < ais.Count; i++) { if (ais[i].GetState() is AIStateAttention) { result = States.Attention; AIStateAttention attention = (AIStateAttention)ais[i].GetState(); if (attention.Cooldown > attentionCooldown) { attentionCooldown = attention.Cooldown; } } else if (ais[i].GetState() is AIStateAggresion) { result = States.Aggresion; AIStateAggresion aggresion = (AIStateAggresion)ais[i].GetState(); if (aggresion.Cooldown > aggresionCooldown) { aggresionCooldown = aggresion.Cooldown; } } else if (ais[i].GetState() is AIStateCover) { result = States.Aggresion; aggresionCooldown = 1; } } AIZone[] zones = AIZone.GetZones(); for (int i = 0; i < zones.Length; i++) { if (zones[i].IsAggression()) { result = States.Aggresion; break; } } if (result == States.Attention) { cooldown = attentionCooldown; } else if (result == States.Aggresion) { cooldown = aggresionCooldown; } return(result); }
private void Awake() { weapon.team = Teams.AI; //Remove auto rotation from navmesh agent, we upate it manualy navMeshAgent.updateRotation = false; hp = maxHP; //Create instances of states idleState = new AIStateIdle(transform.forward); attentionState = new AIStateAttention(); aggresionState = new AIStateAggresion(); sleepState = new AIStateSleep(); coverState = new AIStateCover(); climbState = new AIStateClimb(); //Switch to default state SwitchState(idleState); }