hello >I would like to make a sync float variable for all player same if a player join later the instance I want the float stay the same for all and all time but i don’t know how to do plz help me.
using UdonSharp;
using UnityEngine;
using UnityEngine.UI;
using VRC.SDKBase;
using VRC.Udon;
using VRC.Udon.Common.Interfaces;
[UdonBehaviourSyncMode(BehaviourSyncMode.Manual)]
public class day_and_night : UdonSharpBehaviour
{
[UdonSynced] public bool times;
[UdonSynced] [Range(0f, 360f)] public float timer;
[UdonSynced] [Range(0f, 360f)] public float timers;
public Material day;
public Material night;
public AudioSource day_sound;
public AudioSource night_sound;
public Light light1;
public Light light2;
public Light light3;
public Light light4;
public Light light5;
public Light light6;
public Text day_text;
public void Start()
{
day_sound.enabled = true;
night_sound.enabled = false;
}
public void Update()
{
day_text.text =timer.ToString();
timer += Time.deltaTime;
if (timer >= 360f && times == true)
{
timer = 0f;
times = false;
}
if (timer >= 360f && times == false)
{
timer = 0f;
times = true;
}
if (timer >= 300f && timer <= 359f && times == false)
{
afternoon_day();
}
if (timer >= 300f && timer <= 359f && times == true)
{
night_end();
}
if (timer >= 0f && timer <= 299f && times == false)
{
days();
}
if (timer >= 0f && timer <= 299f && times == true)
{
nights();
}
}
public void UpdateTimer()
{
timers = timer;
}
public void nights()
{
RenderSettings.skybox = night;
light1.intensity = 0.05f;
light2.intensity = 0.05f;
light3.intensity = 0.05f;
light4.intensity = 0.05f;
light5.intensity = 0.05f;
light6.intensity = 0.05f;
night_sound.enabled = true;
day_sound.enabled= false;
}
public void days()
{
RenderSettings.skybox = day;
light1.intensity = 1f;
light2.intensity = 1f;
light3.intensity = 1f;
light4.intensity = 1f;
light5.intensity = 1f;
light6.intensity = 1f;
day_sound.enabled = true;
night_sound.enabled = false;
}
public void afternoon_day()
{
RenderSettings.skybox = day;
light1.intensity = 0.35f;
light2.intensity = 0.35f;
light3.intensity = 0.35f;
light4.intensity = 0.35f;
light5.intensity = 0.35f;
light6.intensity = 0.35f;
}
public void night_end()
{
RenderSettings.skybox = night;
light1.intensity = 0.35f;
light2.intensity = 0.35f;
light3.intensity = 0.35f;
light4.intensity = 0.35f;
light5.intensity = 0.35f;
light6.intensity = 0.35f;
}
public override void OnPlayerJoined(VRCPlayerApi player)
{
SendCustomNetworkEvent(NetworkEventTarget.All, "UpdateTimer");
}
}