static void Main() { Console.WriteLine("Please enter time for waiting in sec"); if (!int.TryParse(Console.ReadLine(), out int time)) { Console.WriteLine("It is not a number"); return; } var countdownMessage = new CountdownMessage(); Listener1 listener1 = new Listener1(countdownMessage); Listener2 listener2 = new Listener2(countdownMessage); countdownMessage.SendNewMessageAfterSleep("Just message", time); listener1.Unregister(countdownMessage); listener2.Unregister(countdownMessage); }
// Server private IEnumerator GameCountdown() { int lastTimeSent = (int)this.countdownTime; // Countdown while (this.countdownTime >= 0.0f) { this.countdownTime -= Time.deltaTime; if ((int)this.countdownTime < lastTimeSent) { lastTimeSent = (int)this.countdownTime; CountdownMessage msg = new CountdownMessage(); msg.countdownString = lastTimeSent <= 0 ? "GO!" : lastTimeSent.ToString(); NetworkServer.SendToAll(CustomMsgType.Countdown, msg); if (msg.countdownString == "GO!") { EnableInputMessage inputMsg = new EnableInputMessage(); for (int i = 0; i < this.numPlayers; i++) { inputMsg.playerId = (int)this.playerInfoList[i].playerObjectId; inputMsg.isEnabled = true; NetworkServer.SendToAll(CustomMsgType.Input, inputMsg); } } } yield return(null); } // Start game this.isPlayingGame = true; }
// Client private void OnGameCountDown(NetworkMessage _networkMessage) { CountdownMessage msg = _networkMessage.ReadMessage <CountdownMessage>(); this.canvasManager.OnGameCountdown(msg.countdownString); }