void FixedUpdate() { if (m_objectiveCheckTrigger) { float sqrDistanceToPlayer = (player.position - transform.position).sqrMagnitude; var nearestBuilding = ResourceManager.GetClosestActiveBuildingTo(transform.position); if (sqrDistanceToPlayer <= (lookRadius * lookRadius)) { if (m_state != EnemyState.AttackingPlayer) { QueueSound(1); } m_state = EnemyState.AttackingPlayer; m_currentTarget = player.position; } else if (nearestBuilding != null && ((nearestBuilding.transform.position - transform.position).sqrMagnitude) <= (lookRadius * lookRadius)) { //print("Triggering Attacking Building"); distanceToBuilding = Vector3.Distance(transform.position, nearestBuilding.transform.position); if (distanceToBuilding <= 10f) { //Explode(); TriggerFuse(); } m_state = EnemyState.AttackingBuilding; //m_currentTarget = nearestBuilding.transform.position; if (m_agent.isOnNavMesh) { m_agent.SetDestination(new Vector3(nearestBuilding.transform.position.x, 0f, nearestBuilding.transform.position.z)); } } else { if (m_aggressive) { m_state = EnemyState.MovingToLocation; m_currentTarget = m_longTermTarget; if (m_agent.isOnNavMesh) { m_agent.SetDestination(m_currentTarget); } } else { m_state = EnemyState.Idle; m_longTermTarget = this.transform.position; m_currentTarget = m_longTermTarget; if (m_agent.isOnNavMesh) { m_agent.SetDestination(m_currentTarget); } //print("Triggering idle"); } } m_objectiveCheckTrigger = false; StartCoroutine("m_objectiveCheck"); } switch (m_state) { case EnemyState.AttackingPlayer: m_currentTarget = player.position; if (m_agent.isOnNavMesh) { m_agent.SetDestination(m_currentTarget); } goingToPlayer = true; break; case EnemyState.AttackingBuilding: break; case EnemyState.Exploading: transform.Rotate(Vector3.up, 10.0f, Space.World); break; case EnemyState.MovingToLocation: if ((transform.position - m_longTermTarget).sqrMagnitude <= (stopDistance * stopDistance)) { m_aggressive = false; StopCoroutine("m_objectiveCheck"); m_state = EnemyState.Idle; m_objectiveCheckTrigger = true; } break; case EnemyState.Idle: default: goingToPlayer = false; break; } }