Problem with variable sync

Hello, I have a question about PUN:

Im using photon cloud in my project and I have read a lot of tutorials but I dont know how to sync one variable from a script to all players in the room...

The problem is the script is in JS and I dont know how to do it, please I really need help I have spent a lot of hours trying to make this... thank you.

I need to sync the variable "Hour" because I want all the players in the room to have the same.

SyncThis1.png


The code from the script (TOD.js) is this:

[code2=javascript]var slider : float;
var slider2 : float;
public var Hour : float;
private var Tod: float;

var sun: Light;

var speed = 50;

var NightFogColor : Color;
var DuskFogColor : Color;
var MorningFogColor : Color;
var MiddayFogColor : Color;

var NightAmbientLight : Color;
var DuskAmbientLight : Color;
var MorningAmbientLight : Color;
var MiddayAmbientLight : Color;

var NightTint : Color;
var DuskTint : Color;
var MorningTint : Color;
var MiddayTint : Color;

var SkyBoxMaterial1 : Material;
var SkyBoxMaterial2 : Material;

var SunNight : Color;
var SunDay : Color;

//THIS WAS ADDED IN TUTORIAL NUMBER 24. It allows for changing the color that reflects of a water object.
//Uncheck IncludeWater if you are not interested in using this.
var Water : GameObject;
var IncludeWater = false;
var WaterNight : Color;
var WaterDay : Color;


function OnGUI () {

if(slider >= 1.0)
{
slider = 0;
}

slider= GUI.HorizontalSlider( Rect(20,20,200,30), slider, 0,1.0);
Hour= slider*24;
Tod= slider2*24;
sun.transform.localEulerAngles = Vector3((slider*360)-90, 0, 0);
slider = slider +Time.deltaTime/speed;
sun.color = Color.Lerp (SunNight, SunDay, slider*2);

//THIS WAS ADDED IN TUTORIAL NUMBER 24. It allows for changing the color that reflects of a water object.
//Uncheck IncludeWater if you are not interested in using this.
if (IncludeWater == true)
{
Water.renderer.material.SetColor("_horizonColor", Color.Lerp (WaterNight, WaterDay, slider2*2-0.2));
}

if(slider<0.5){
slider2= slider;
}
if(slider>0.5){
slider2= (1-slider);
}
sun.intensity = (slider2-0.2)*1.7;


if(Tod<4){
//it is Night
RenderSettings.skybox=SkyBoxMaterial1;
RenderSettings.skybox.SetFloat("_Blend", 0);
SkyBoxMaterial1.SetColor ("_Tint", NightTint);
RenderSettings.ambientLight = NightAmbientLight;
RenderSettings.fogColor = NightFogColor;
}
if(Tod>4&&Tod<6){
RenderSettings.skybox=SkyBoxMaterial1;
RenderSettings.skybox.SetFloat("_Blend", 0);
RenderSettings.skybox.SetFloat("_Blend", (Tod/2)-2);
SkyBoxMaterial1.SetColor ("_Tint", Color.Lerp (NightTint, DuskTint, (Tod/2)-2) );
RenderSettings.ambientLight = Color.Lerp (NightAmbientLight, DuskAmbientLight, (Tod/2)-2);
RenderSettings.fogColor = Color.Lerp (NightFogColor,DuskFogColor, (Tod/2)-2);
//it is Dusk

}
if(Tod>6&&Tod<8){
RenderSettings.skybox=SkyBoxMaterial2;
RenderSettings.skybox.SetFloat("_Blend", 0);
RenderSettings.skybox.SetFloat("_Blend", (Tod/2)-3);
SkyBoxMaterial2.SetColor ("_Tint", Color.Lerp (DuskTint,MorningTint, (Tod/2)-3) );
RenderSettings.ambientLight = Color.Lerp (DuskAmbientLight, MorningAmbientLight, (Tod/2)-3);
RenderSettings.fogColor = Color.Lerp (DuskFogColor,MorningFogColor, (Tod/2)-3);
//it is Morning

}
if(Tod>8&&Tod<10){
RenderSettings.ambientLight = MiddayAmbientLight;
RenderSettings.skybox=SkyBoxMaterial2;
RenderSettings.skybox.SetFloat("_Blend", 1);
SkyBoxMaterial2.SetColor ("_Tint", Color.Lerp (MorningTint,MiddayTint, (Tod/2)-4) );
RenderSettings.ambientLight = Color.Lerp (MorningAmbientLight, MiddayAmbientLight, (Tod/2)-4);
RenderSettings.fogColor = Color.Lerp (MorningFogColor,MiddayFogColor, (Tod/2)-4);

//it is getting Midday

}
}[/code2]


Please help me with this, if I can learn how this should be done correctly I will know how to do a lot of things more using PUN.

Excuse my English and thank you.

Comments

  • Do you want to write the sync code in JS or in C#?
    If you code in one language and want to access classes from the other, you need to make sure that the "other" language is compiled first by Unity. You can place JS in a "Plugins" folder and it gets compiled early and you can access it from C# code that's not in a "Plugins" folder.
    It's basically a Unity problem. I think you can learn more about it here:
    http://docs.unity3d.com/Documentation/M ... lders.html
  • Thank you for your reply.

    I already fixed my problem, I rewrite the code in C#, then attached PhotonView with the TOD.cs at Observe, and in TOD.cs I write the OnSerialize and all that of Photon.