- Home /
How to set count-down timer for a muli-player game in C# UNET? The timer must only start when all the players are connected.
I want a C# script for multi-player countdown timer.
Answer by look001 · Jul 28, 2017 at 11:41 AM
http://answers.unity3d.com/questions/225213/c-countdown-timer.html Use that solution together. Put it in an if with a bool as conditon that switches to true if all players are connected. Combine this with a server that sends a start instruction to the client.
Thanks! But I already knew how to make a timer for offline games. I have written the following code for multi-player but its not working as per requirement. Server timer starts before the client is connected and then client takes the value from server timer and starts from there.
void TimerOnServer()
{
if (isServer)
{
if (timer > 0.0f)
{
timer -= Time.deltaTime;
timerText.text = $$anonymous$$utes.ToString() + ":" + seconds.ToString("00");
}
else
{
playPanel.SetActive(true);
timerText.text = "0:00";
Time.timeScale = 0.0f;
}
}
}
void TimerOnClient()
{
if (isClient)
{
localTimer = timer;
timerText.text = local$$anonymous$$inutes.ToString() + ":" + localSeconds.ToString("00");
if(localTimer <= 0.0f)
{
playPanel.SetActive(true);
timerText.text = "0:00";
Time.timeScale = 0.0f;
}
}
}
Your answer
Follow this Question
Related Questions
Photon Networking not synchronizing 0 Answers
Unet: Discern between user disconnection and connection lost 1 Answer
How to clean buffer after some time? 0 Answers
UNet - Connecting and Testing a 'choose your character' scenario 0 Answers
Best way to choose Google Play Realtime Multiplayer Host? 0 Answers