Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question synchronize Game Timer in Photon

Discussion in 'Matchmaker' started by bhuvneet, Oct 11, 2023.

  1. bhuvneet

    bhuvneet

    Joined:
    Jun 26, 2022
    Posts:
    6
    I am making a room timer for photon, the timer working fine for the master but shows null reference for client.
    the second else statement in start function shows null reference on client


    Code (CSharp):
    1. bool startTimer = false;
    2. double timerIncrementValue;
    3. double startTime;
    4. [SerializeField] double timer = 20;
    5. ExitGames.Client.Photon.Hashtable CustomeValue;
    6.  
    7. void Start()
    8.     {
    9.         if (PhotonNetwork.player.IsMasterClient)
    10.         {
    11.             CustomeValue = new ExitGames.Client.Photon.Hashtable();
    12.             startTime = PhotonNetwork.Time;
    13.             startTimer = true;
    14.             CustomeValue.Add("StartTime", startTime);
    15.             PhotonNetwork.CurrentRoom.SetCustomProperties(CustomeValue);
    16.         }
    17.         else
    18.         {
    19.             startTime = double.Parse(PhotonNetwork.CurrentRoom.CustomProperties["StartTime"].ToString());
    20.             startTimer = true;
    21.         }
    22.     }
    23.  
    24. void Update()
    25.     {
    26.  
    27.         if (!startTimer) return;
    28.  
    29.         timerIncrementValue = PhotonNetwork.Time - startTime;
    30.  
    31.         if (timerIncrementValue >= timer)
    32.         {
    33.            //Timer Completed
    34.            //
    35.         }
    36.     }
     
  2. MarcoZVincenzi

    MarcoZVincenzi

    Joined:
    Mar 3, 2022
    Posts:
    15
    Hey, just do you know, these are the Unity Matchmaker forums. You'll likely get better answers over at the Photon Forums.
     
  3. bhuvneet

    bhuvneet

    Joined:
    Jun 26, 2022
    Posts:
    6
    they are dead now