Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Photon.Pun;
- using Photon.Realtime;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Hashtable = ExitGames.Client.Photon.Hashtable;
- public class PhotonTimer : MonoBehaviour
- {
- #region SINGLETON
- public static PhotonTimer Singleton
- {
- get
- {
- return GameObject.FindObjectOfType<PhotonTimer>();
- }
- }
- #endregion
- public bool startTimer = false;
- [Space(10)]
- public double milliseconds;
- public int seconds;
- public int minutes;
- [Space(10)]
- double startTime;
- double timerIncrementValue;
- [SerializeField] double timer = 20;
- ExitGames.Client.Photon.Hashtable CustomeValue;
- void OnEnable()
- {
- if (!PhotonNetwork.IsConnected)
- return;
- if (PhotonNetwork.IsMasterClient)
- {
- CustomeValue = new ExitGames.Client.Photon.Hashtable();
- startTime = PhotonNetwork.Time;
- startTimer = true;
- CustomeValue.Add("StartTime", startTime);
- PhotonNetwork.CurrentRoom.SetCustomProperties(CustomeValue);
- }
- else
- {
- startTime = double.Parse(PhotonNetwork.CurrentRoom.CustomProperties["StartTime"].ToString());
- startTimer = true;
- }
- }
- void Update()
- {
- if (!startTimer)
- return;
- if (PhotonNetwork.IsConnected)
- {
- timerIncrementValue = PhotonNetwork.Time - startTime;
- milliseconds = timerIncrementValue % 1;
- seconds = (int)timerIncrementValue % 60;
- minutes = (int)timerIncrementValue / 60;
- if (timerIncrementValue >= timer)
- {
- //Timer Completed
- //Do What Ever You What to Do Here
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment