Skip to content

Instantly share code, notes, and snippets.

@JT5D
Forked from unitycoder/GetSliderValue
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save JT5D/0b5205bad8ba368a1117 to your computer and use it in GitHub Desktop.

Select an option

Save JT5D/0b5205bad8ba368a1117 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class GetSliderValue : MonoBehaviour {
public YourScript yourScript;
void Awake ()
{
if (yourScript==null) Debug.LogError("No yourScript assigned at "+transform.name);
var slider = GetComponent<Slider>();
slider.value = yourScript.sliderValue; // init with value from script
slider.onValueChanged.AddListener((value) => { yourScript.sliderValue = value; }); // send value
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment