Hello I am searching for days on how to make match timer that when that time finishes the match ends.
Now I am using this code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using TMPro;
using Photon.Realtime;
public class Timer : MonoBehaviourPunCallbacks
{
bool startTimer = false;
double timerIncrementValue;
double startTime;
public static double timer;
ExitGames.Client.Photon.Hashtable CustomeValue;
public GameObject scoreBoard, scoreManager;
public TMP_Text timerUI;
void Start()
{
if (PhotonNetwork.LocalPlayer.IsMasterClient)
{
CustomeValue = new ExitGames.Client.Photon.Hashtable();
startTime = PhotonNetwork.Time;
CustomeValue.Add("StartTime", startTime);
PhotonNetwork.CurrentRoom.SetCustomProperties(CustomeValue);
startTimer = true;
Debug.Log("Going to send to client");
} else
{
SendToClient();
}
}
void SendToClient()
{
Debug.Log("Checkign If we are not");
startTime = double.Parse(PhotonNetwork.CurrentRoom.CustomProperties["StartTime"].ToString());
Debug.Log(startTime + " Client Time");
startTimer = true;
}
void Update()
{
if (!startTimer) return;
timerIncrementValue = PhotonNetwork.Time - startTime;
timerUI.text = timerIncrementValue.ToString();
if (timerIncrementValue >= timer)
{
if(PhotonNetwork.LocalPlayer.IsMasterClient)
{
photonView.RPC("endGame", RpcTarget.All);
}
}
}
[PunRPC]
void endGame()
{
EndGame();
}
public void EndGame()
{
//PlayerMulti.playerMulti.Allcanvas.SetActive(false);
scoreBoard.SetActive(true);
scoreManager.SetActive(true);
}
}
It always showed me there is a problem at this line of code
startTime = double.Parse(PhotonNetwork.CurrentRoom.CustomProperties["StartTime"].ToString());
I really dont know what to do and I cant find a solution for it.
Thank You