Hello,i am pretty new in scripting and i got this problem : The problems appear when i am a client.If i am the server everything is ok.So,as you can see i am trying to send a value from a variable that only the server owns to the client.Only 1 way.Let's say that I want to send the client the current server time.Why if i print DispTemp inside SetVariable function i get the right number(25) and if i print it outside it i get something like : 100 and then 25 and then 100 and then 25 and so on...So this way when i use if(networkView.isMine && Network.isClient){ GUI.Box(new Rect(0,0,Screen.width / 16,Screen.height / 32),DispTemp + "C");} i'll always get 100 instead of 25 :S. As far as i noticed,DispTemp = 25 only when !networkView.isMine :S How can i make it to be equal with the value boadcasted by the server all of the time? Please help me and thanks in advance.An anwser in JavaScript would be welcome aswell :D
using UnityEngine;
using System.Collections;
public class MonoTestVar : MonoBehaviour {
int Temp = 25;
int DispTemp = 100;
void Update(){
Debug.Log(DispTemp);
if(Network.isServer && networkView.isMine){
networkView.RPC("SetVariable", RPCMode.All, Temp);}
}
[RPC]
void SetVariable(int newTemp){
//This RPC is in this case always called by the server,
// but executed on all the clients
DispTemp = newTemp;
}
void OnGUI(){
if(networkView.isMine && Network.isClient){
GUI.Box(new Rect(0,0,Screen.width / 16,Screen.height / 32),DispTemp + "C");}
if(networkView.isMine && Network.isServer){
GUI.Box(new Rect(0,0,Screen.width / 16,Screen.height / 32),DispTemp + "C");}
}
}