Skip to content

Instantly share code, notes, and snippets.

@mtytheone
Last active April 15, 2020 06:59
Show Gist options
  • Save mtytheone/ee751b3e60ca4794ed84a4ed5270e6b0 to your computer and use it in GitHub Desktop.
Save mtytheone/ee751b3e60ca4794ed84a4ed5270e6b0 to your computer and use it in GitHub Desktop.
using UdonSharp;
using UnityEngine;
using UnityEngine.UI;
using VRC.SDKBase;
using VRC.Udon;
public class SyncSlider : UdonSharpBehaviour
{
[SerializeField] Slider _slider;
[SerializeField] Text _text;
[SerializeField] Text _ownerText;
[UdonSynced(UdonSyncMode.None)]
float _sliderValue;
void LateUpdate()
{
_slider.value = _sliderValue;
_text.text = _sliderValue.ToString("F2");
_ownerText.text = Networking.GetOwner(this.gameObject).displayName;
}
public void SetValue() //OnValueChangedで呼ぶ
{
_sliderValue = _slider.value;
}
public void ChangerOwner() //EventTriggerで呼ぶ
{
if (!Networking.IsOwner(Networking.LocalPlayer, this.gameObject)) Networking.SetOwner(Networking.LocalPlayer, this.gameObject);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment