//-------------------------------------------------------------------------------------- // SoldierMovement: Function for the current soldiers movement. // // Param: // sCurrentSoldier: A SoldierActor object for which soldier wants to move. //-------------------------------------------------------------------------------------- void SoldierMovement(SoldierActor sCurrentSoldier) { // Get the horizontal and vertical axis. float fMoveHorizontal = Input.GetAxis("Horizontal"); float fMoveVertical = Input.GetAxis("Vertical"); // Apply Axis to the current soldier. sCurrentSoldier.Move(fMoveHorizontal, fMoveVertical); }
//-------------------------------------------------------------------------------------- // Update: Function that calls each frame to update game objects. //-------------------------------------------------------------------------------------- void Update() { // Check if it is this players turn. if (m_nPlayerNumber == TurnManager.m_snCurrentTurn) { // Get the soldier object and script. GameObject gCurrentSoldier = GetSoldier(m_nSoldierTurn); SoldierActor sCurrentSoldier = gCurrentSoldier.GetComponent <SoldierActor>(); // if in the turns action state. if (StateMachine.GetState() == ETurnManagerStates.ETURN_ACTION) { // If not paused then can move and shoot. if (!PauseManager.m_sbPaused) { // Update the mouse face function in soldier. sCurrentSoldier.FaceMouse(); // if not over a button or the mouse is held if (!EventSystem.current.IsPointerOverGameObject() || m_bMouseHeld) { // Get the mouse input functions. MouseDown(sCurrentSoldier); m_bMouseHeld = MouseHeld(sCurrentSoldier); MouseUp(sCurrentSoldier); } // if the mouse is not held. if (!m_bMouseHeld) { // Switch soldier weapon on key presses. SwitchWeapon(sCurrentSoldier); // Move the soldier. SoldierMovement(sCurrentSoldier); } // if mouse held. else if (m_bMouseHeld) { // stop the current soldier from moving. sCurrentSoldier.Move(0, 0); } } } // if in the end turn state. else if (StateMachine.GetState() == ETurnManagerStates.ETURN_END) { // stop the current soldier from moving. sCurrentSoldier.Move(0, 0); } } // Set Active soldier count to 0 m_nActiveSoldiers = 0; // Go through each soldier and count how many are alive. for (int i = 0; i < m_agSoldierList.Length; ++i) { // if the soldier is active. if (m_agSoldierList[i].activeInHierarchy) { // Get soldier script. SoldierActor s = m_agSoldierList[i].GetComponent <SoldierActor>(); // soldier is alive. if (s.m_fCurrentHealth > 0) { // increment the active soldier number by 1. m_nActiveSoldiers += 1; } } } }