ready for matchmaking

This commit is contained in:
2026-02-15 11:34:04 +05:30
parent 02dee0b86d
commit b7d8bb1c8c
4 changed files with 507 additions and 18 deletions
+10
View File
@@ -11,6 +11,8 @@ public class GameCanvas : MonoBehaviour
void Awake()
{
instance = this;
ShowWaitingForOpponentPanel();
}
public EventTrigger gameInputPanel;
@@ -22,8 +24,16 @@ public class GameCanvas : MonoBehaviour
public TMP_Text txtTurnTimer;
public Image turnTimerRound;
public GameObject waitingForOpponentPanel;
public void ShowWaitingForOpponentPanel(){
waitingForOpponentPanel.SetActive(true);
}
public void HideWaitingForOpponentPanel(){
waitingForOpponentPanel.SetActive(false);
}
void Update(){
UpdateTurnTimer();
}
+45 -8
View File
@@ -16,6 +16,16 @@ public class GameManager : NetworkBehaviour
}
[SyncVar]
public bool m_isMoving =false;
[SyncVar(hook = nameof(OnGameStartedChanged))]
public bool gameStarted = false;
void OnGameStartedChanged(bool oldStarted, bool newStarted){
if(newStarted){
GameCanvas.instance.HideWaitingForOpponentPanel();
}else{
GameCanvas.instance.ShowWaitingForOpponentPanel();
}
}
[SyncVar(hook = nameof(OnSelectedTeamChanged))]
public Team SelectedTeam = Team.Red;
void OnSelectedTeamChanged(Team oldTeam, Team newTeam){
@@ -55,6 +65,9 @@ public class GameManager : NetworkBehaviour
[SyncVar]
public int hitCounter = 0;
public static GameManager instance;
public float puckMass{
@@ -234,12 +247,23 @@ public class GameManager : NetworkBehaviour
m_isMoving=IsMoving();
HandleTurnTimer();
if(!gameStarted){
NetPlayer[] players = FindObjectsOfType<NetPlayer>();
if (players.Length == 2)
{
gameStarted = true;
GameCanvas.instance.HideWaitingForOpponentPanel();
Debug.Log("Game started On Server");
}
}
}
}
void HandleTurnTimer(){
if(turnTimerCounter < turnTimer){
if(!isMoving && !switchingTeams){
if(!isMoving && !switchingTeams && gameStarted){
turnTimerCounter += Time.deltaTime;
}
}else{
@@ -275,14 +299,11 @@ public class GameManager : NetworkBehaviour
if(blueScore >= 3){
gameOverPanel.SetActive(true);
blueWon.SetActive(true);
redWon.SetActive(false);
RpcGameOver(Team.Blue);
gameOver(Team.Blue);
}else if(redScore >= 3){
gameOverPanel.SetActive(true);
blueWon.SetActive(false);
redWon.SetActive(true);
RpcGameOver(Team.Red);
gameOver(Team.Red);
}else{
StartCoroutine(CoroutineOnGoal(team));
}
@@ -290,6 +311,22 @@ public class GameManager : NetworkBehaviour
hitCounter = 0;
}
[ClientRpc]
void RpcGameOver(Team team){
gameOver(team);
}
void gameOver(Team team){
gameOverPanel.SetActive(true);
if(team == Team.Blue){
blueWon.SetActive(true);
redWon.SetActive(false);
}else{
blueWon.SetActive(false);
redWon.SetActive(true);
}
}
bool freezeInput = false;
IEnumerator CoroutineOnGoal(Team team, bool kickoff = false){