Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Last active August 29, 2015 14:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save unitycoder/ff21351eb643852a13ce to your computer and use it in GitHub Desktop.
Save unitycoder/ff21351eb643852a13ce to your computer and use it in GitHub Desktop.
Get UI Slider Value
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