Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Fokesy · May 26 at 07:02 AM · photontimer countdown

Unity3D Photon - Timer & Rounds


Hey, im trying to setup a timer and rounds in my multiplayer game using photon.


I have it working on the master client, but it doesn't sync on all clients properly.


i have a simplified version of my code, which ill post below. Thankyou for your time.


 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using Photon.Pun;
 using UnityEngine.SceneManagement;
 using UnityEngine.UI;
 
 public class InGameManager : MonoBehaviourPunCallbacks
 {
     public Text roomTimerText;
     public Text roundText;
     public int currentRound;
     public int MultiplayercurrentRound;
     public int totalRounds;
     public int Timer;
     public int MultiplayerTimer;
     public int RoundTime;
     public int hostSelectionTime;
     public bool flick;
     public bool flick2;
     public bool startedRound;
     public bool startedsync;
     public PhotonView PV;
     public GameObject pm;
 
     void Awake ()
     {
         PV = GetComponent<PhotonView>();
     }
 
     void OnSceneLoaded ( Scene scene , LoadSceneMode loadSceneMode )
     {
         if( PhotonNetwork.IsMasterClient )
         {
             Timer = RoundTime;
             StartRound();
         }
     }
 
     void Update ()
     {
         if( startedRound && Timer==0 && currentRound==totalRounds )
         {
             Application.LoadLevel( "Menu" );
         }
 
         float minutes = Mathf.FloorToInt(Timer / 60);
         float seconds = Mathf.FloorToInt(Timer % 60);
         roundText.text = $"{currentRound} / {totalRounds}";
         roomTimerText.text = $"{minutes:00}:{seconds:00}";
 
         if( PhotonNetwork.IsMasterClient )
         {
             startedsync = startedRound;
             MultiplayerTimer = Timer;
             MultiplayercurrentRound = currentRound;
             PV.RPC("SyncTime", RpcTarget.All, MultiplayerTimer);
             PV.RPC("SyncRound", RpcTarget.All, MultiplayercurrentRound);
             PV.RPC("startRoundbool", RpcTarget.All, startedsync);
 
             if( !flick && startedRound )
             {
                 StartCoroutine( time() );
             }
 
             if( !flick2 && !startedRound )
             {
                 StartCoroutine( roundstartdelay() );
             }
 
             if( !startedRound && Timer==0 )
             {
                 startedRound = true;
                 Timer = RoundTime;
             }
 
             if( startedRound && Timer==0 )
             {
                 startedRound = false;
                 StartRound();
                 currentRound += 1;
             }
         }
     }
 
     [PunRPC]
     void SyncTime ( int time )
     {
         Timer = time;
     }
 
     [PunRPC]
     void SyncRound ( int round )
     {
         currentRound = round;
     }
 
     [PunRPC]
     void startRoundbool ( bool sr )
     {
         startedRound = sr;
     }
 
     void StartRound ()
     {
         Timer = hostSelectionTime;
     }
 
     IEnumerator roundstartdelay ()
     {
         flick2 = true;
         yield return new WaitForSeconds(1);
         Timer -= 1;
         flick2 = false;
     }
 
     IEnumerator time ()
     {
         flick = true;
         yield return new WaitForSeconds(1);
         Timer -= 1;
         flick = false;
     }
 
 }


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Fokesy · yesterday

I got it working by using customroomproperties intead.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

141 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how to assign same randomly choosen time to both players in muliplayer photon? 1 Answer

NullReferenceException 0 Answers

A MindBreaking MonoBehaviour Issue!. (Unity3D v5.1.0f Pro: unityserializer-ng VS Photon Unity Networking) 0 Answers

Unity Audio Networking Stops Playing after 10s 0 Answers

Both players reach same time how to get result draw in photon unity 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges