I’m trying to figure out to implement whoever has the greater score wins the round but there are four teams how do I figure out who has the greatest score at the end of the round
my code
public void Update()
{
if (_timer <= 0f)
{
Debug.Log("Round is over");
DetermineRoundWin();
currentround++;
_timer = timer;
}
_timer -= Time.deltaTime;
i was thinking of using if statements comparing two teams but I have four so I don’t want to have 16 if statements to determine who wins the round I just can’t wrap my head around it
int w, x, y, z
string winner = “none”;
if(w > x && w > y && w > z) winner = “W”
else if(x > w && x > y && x > z) winner = “X”
else if(y > x && y > w && y > z) winner = “Y”
else winner = “Z”
Does not check an even score though.
I’m sure there’s a better way but here’s a simply idea.
@SamohtVII didnt fit since its 3000 characters sent it in an answer instead hope it doesnt bother you
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameModeManager : MonoBehaviour {
[SerializeField]
private float _timer;
public float timer;
public int maxRounds = 36;
[SerializeField]
int currentround;
[SerializeField]
private int team1RoundScore;
[SerializeField]
private int team2RoundScore;
[SerializeField]
private int team3RoundScore;
[SerializeField]
private int team4RoundScore;
public int team1Players;
public int team2Players;
public int team3Players;
public int team4Players;
private bool team1wins;
private bool team2wins;
private bool team3wins;
private bool team4wins;
public int team1score;
public int team2score;
public int team3score;
public int team4score;
[SerializeField]
private int endwins;
//[SerializeField]
//bool checkgameEnd;
[SerializeField]
bool gameFinished;
public void Update()
{
if (_timer <= 0f)
{
Debug.Log(team1score + team2score + team3score + team4score);
if (team1score > team2score && team1score > team3score && team1score > team4score)
{
//team 1 wins round
team1RoundScore++;
}
else if (team2score > team1score && team2score > team3score && team2score > team4score)
{
//team 2 wins round
team2RoundScore++;
}
else if (team3score > team2score && team3score > team1score && team3score > team4score)
{
//team 3 wins round
team3RoundScore++;
}
else
{
//team 4 wins round
team4RoundScore++;
}
currentround++;
_timer = timer;
}
_timer -= Time.deltaTime;
if (currentround == maxRounds)
{
determineWin();
}
}
private void determineWin()
{
if (team1RoundScore == 8)
{
//team 1 wins
endwins++;
team1wins = true;
}
if (team2RoundScore == 8)
{
//team 2 wins
endwins++;
team2wins = true;
}
if (team3RoundScore == 8)
{
//team 3 wins
endwins++;
team3wins = true;
}
if (team4RoundScore == 8)
{
//team 4 wins
endwins++;
team4wins = true;
}
if (team1RoundScore <= 8)
{
//remove team 1
}
if (team2RoundScore <= 8)
{
//remove team 2
}
if (team3RoundScore <= 8)
{
//remove team3
}
if (team4RoundScore <= 8)
{
//remove team4
}
determineOvertime();
}
private void determineOvertime()
{
if (endwins == 1) {
if (team1wins)
GameCompleted("Team 1 wins");
if (team2wins)
GameCompleted("Team 2 wins");
if (team3wins)
GameCompleted("Team 3 wins");
if (team4wins)
GameCompleted("Team 4 wins");
}
if (endwins > 1) {
BeginOverTime();
}
}
private void BeginOverTime()
{
//display who wins
if (team1RoundScore == 9)
{
//team 1 wins
GameCompleted("Team 1 won");
}
if (team2RoundScore == 9)
{
//team 2 wins
GameCompleted("Team 2 won");
}
if (team3RoundScore == 9)
{
//team 3 wins
GameCompleted("Team 3 won");
}
if (team4RoundScore == 9)
{
//team 4 wins
GameCompleted("Team 4 won");
}
}
private void GameCompleted(string whoWon)
{
gameFinished = true;
Debug.Log(whoWon);
}
}