public void SquadSelected(SquadControl selectedSquad) { if (selectedSquad.squadType == SquadControl.SquadType.Enemy) { squad.Attack(selectedSquad); } }
public void TakeTurn() { SquadControl[] possibleMeleeTargets = squad.GetAttackTargets(); bool playerVisible = CanSeePlayer(); int directionToPlayer = 0; if (playerVisible) { directionToPlayer = GetOrthagonalDirection(gameManager.PlayerSquad.transform); } bool shouldMove = false; Vector3 moveDirection = Vector3.zero; bool shouldRotate = false; int rotateDirection = 0; bool shouldAttack = false; SquadControl attackTarget = null; switch (currentState) { case AIState.Waiting: if (possibleMeleeTargets.Length > 0) { ChangeState(AIState.Chasing); shouldAttack = true; attackTarget = possibleMeleeTargets[0]; } if (playerVisible) { ChangeState(AIState.Chasing); } break; case AIState.Patrolling: break; case AIState.Chasing: Debug.Log("directionToPlayer: " + directionToPlayer); if (!playerVisible && possibleMeleeTargets.Length == 0) { ChangeState(AIState.Waiting); } if (possibleMeleeTargets.Length > 0) { Debug.Log("Should Attack"); shouldAttack = true; attackTarget = possibleMeleeTargets[0]; } else if (directionToPlayer < 0.1f) { shouldMove = true; moveDirection = transform.forward; } else { shouldRotate = true; rotateDirection = Mathf.Clamp(directionToPlayer, -1, 1); } break; } if (shouldAttack) { Debug.Log(transform.name + " is Attacking"); squad.Attack(attackTarget); } else if (shouldMove) { Debug.Log(transform.name + " is Moving"); squad.Move(moveDirection); } else if (shouldRotate) { Debug.Log(transform.name + " is Rotating"); squad.Rotate(rotateDirection); } else { Debug.Log(transform.name + " is Passing"); squad.CompleteTurn(); } }