Quantcast
Channel: Latest Questions by brandonhotdo
Viewing all articles
Browse latest Browse all 108

Syncing times

$
0
0
So I have a day/night cycle but the problem is when you make the server it starts of day by default and lets say you waited to the afternoon, then when a new player joins for him it's the morning and the afternoon still for you (btw morning is the default time). using UnityEngine; using System.Collections; public class Global_Time : MonoBehaviour { public float slider; public float slider2; public float Hour; private float Tod; int speed = 600; // Use this for initialization void Start () { } // Update is called once per frame void Update () { networkView.RPC ("PlayTime",RPCMode.AllBuffered); } [RPC] public void PlayTime(){ if(slider >= 1.0) { slider = 0; } Hour = slider*24; Tod = slider2*24; slider = slider +Time.deltaTime/speed; if(slider<0.5){ slider2= slider; } if(slider>0.5){ slider2= (1-slider); } } void OnGUI(){ GUI.Label(new Rect(50,50,100,200),slider.ToString()); GUI.Label(new Rect(50,70,100,200),slider2.ToString()); GUI.Label(new Rect(50,90,100,200),Hour.ToString()); } } there's the code for analysis. So what I want done is that no matter what client it is or how late he joins the server for the public floats to be the same on all clients (i have put a network manager on it).

Viewing all articles
Browse latest Browse all 108

Trending Articles