Last active
August 29, 2015 14:18
-
-
Save unitycoder/ff21351eb643852a13ce to your computer and use it in GitHub Desktop.
Get UI Slider Value
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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