// This function is to find out if there is a winner of the round. // This function is called with the assumption that 1 or fewer tanks are currently active. private TankManagerCoin GetRoundWinner() { // Go through all the tanks... int max = 0; //TankManager winner; // ... and if one of them is active, it is the winner so return it. /*if (m_Tanks[0].m_Coin.coins>m_Tanks[1].m_Coin.coins){ * // max = m_Tanks[i].m_Coin.coins; * Debug.Log(max); * return m_Tanks[0]; * }else return m_Tanks[1];*/ for (int i = 0; i < m_Tanks.Length; i++) { // ... and if they are active, increment the counter. if (m_Tanks[i].m_Coin.coins > max) { max = m_Tanks[i].m_Coin.coins; win = m_Tanks[i]; } } return(win); // If none of the tanks are active it is a draw so return null. // return null; }
private IEnumerator RoundEnding() { // Stop tanks from moving. DisableTankControl(); // Clear the winner from the previous round. m_RoundWinner = null; // See if there is a winner now the round is over. m_RoundWinner = GetRoundWinner(); // If there is a winner, increment their score. if (m_RoundWinner != null) { m_RoundWinner.m_Wins++; } // Now the winner's score has been incremented, see if someone has one the game. m_GameWinner = GetGameWinner(); // Get a message based on the scores and whether or not there is a game winner and display it. string message = EndMessage(); m_MessageText.text = message; // Wait for the specified length of time until yielding control back to the game loop. yield return(m_EndWait); }