Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

How to make a round time in photon cloud room?

Discussion in 'Multiplayer' started by dmitry-K, Oct 26, 2014.

  1. dmitry-K

    dmitry-K

    Joined:
    Apr 2, 2014
    Posts:
    26
    Hello.
    How to make round timer to make every player leave room in one moment?
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,957
    Look for "InRoomRoundTimer" in the project. In best case, you do a new scene and add this script and the "ConnectAndJoinRandom" script to the cam. Build and run this.
    You can see that a round timer is synchronized with the InRoomRoundTimer. It simply sets a PhotonNetwork.time timestamp as room Custom Property and uses that to sync a round time.
    Use parts of that script as you need them to get your own timer to run and end the game.
     
  3. JamesArndt

    JamesArndt

    Unity Technologies

    Joined:
    Dec 1, 2009
    Posts:
    2,882
    I'm using this script as a base (InRoomRoundTimer) , but I'm having an issue where the players join the room, and before they instantiate in the scene a standby camera is flying through the scene. During the time before they click their team choice button, the timer is still going so players start with time already having progressed. I think it has to do with the PhotonNetwork.time starting at the launch of the scene. I've tried everything to get it to hold the timer, but it won't. Any suggestions as to what to do in my scenario?
     
  4. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,957
    The InRoomRoundTimer is global for the room, so it's probably not useful when individual players might be late and or view a cutscene first.
    You probably should have 1 timer per player who joins. Force them to be ready within X seconds for the game to start.
    When the match starts with all ready players, then set the round timer (the actual match starts).
    Before the match starts and after it ends, the round timer must be ignored.
     
  5. RamonesAbreu

    RamonesAbreu

    Joined:
    Nov 21, 2017
    Posts:
    2
    You could capture the elapsed time until the players start the game and then subtract it from the InRoomRoundTimer in a local variable. Remember to check only on masterClient to avoid sync errors

    Code (CSharp):
    1. var photonTimer InRoomRoundTimer;
    2.  
    3. var timerUntilStart;
    4.  
    5. var roundTimer;
    6.  
    7. void Start()
    8. {
    9.      timerUntilStart += Time.deltaTime; //only in masterClient
    10. }
    11.  
    12. void OnStartMatch()
    13. {
    14.       roundTimer = InRoomRoundTimer - timerUntilStart;
    15. }