TheKingsRace/Assets/Scripts/Game/PlayerHUD.cs
Julia Butenhoff 8dcb4e11af Adjusted Respawn Delay and Added Respawning Text
- Respawning now takes 3 seconds
- Host also now must wait the same 3 seconds like the clients did
- Added a screen with text that says respawning so players are informed
  of what is happening
2022-01-29 00:12:28 -06:00

52 lines
1.3 KiB
C#

using MLAPI;
using MLAPI.Messaging;
using MLAPI.SceneManagement;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class PlayerHUD : NetworkBehaviour
{
[SerializeField] private int raceTimer;
public TMP_Text countdown_text;
public TMP_Text spectating_text;
[SerializeField] private GameObject respawningPanel;
// Start is called before the first frame update
void Start() {
respawningPanel.SetActive(false);
countdown_text.text = "Time Remaining: 00:00";
StartCoroutine(RaceTimeCountdown());
}
IEnumerator RaceTimeCountdown() {
for (int i = raceTimer; i >= 0; i--) {
int minutes = i / 60;
int seconds = i % 60;
countdown_text.text = "Time Remaining: " + minutes.ToString("D2") + ":" + seconds.ToString("D2");
yield return new WaitForSeconds(1f);
}
// Timer is over
// Only have the host call the server RPC to it is only done once
if (IsHost) {
EndRoundServerRPC();
}
}
[ServerRpc]
private void EndRoundServerRPC() {
NetworkSceneManager.SwitchScene("PostGame");
}
public void setRespawnPanelVisibility(bool state) {
respawningPanel.SetActive(state);
}
}