Unity 4.6B UI Scrollbar Usage

Hey Unitarians,

I’ve downloaded the new 4.6 Beta UI, and it works for the most part, flawlessly. However, I’m confused on how to use the new scrollbar. I can get it to change it’s value in game, but how would I detect the value and add it to playerprefs? Here is my code:

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class MainMenuController : MonoBehaviour {

	public Scrollbar SensitivityBar;
	private float tempSensitivity;
	private float SensitivityValue;

	void Start () {
		if(PlayerPrefs.HasKey("Sensitivity")){
			SensitivityValue = PlayerPrefs.GetFloat ("Sensitivity");
		}else{
			SensitivityValue = 0.5f;
		}
		SensitivityBar.value = SensitivityValue;
		tempSensitivity = SensitivityValue;
	}

	void Update () {
		SensitivityValue = SensitivityBar.value;
		if(SensitivityValue != tempSensitivity) {
			SensitivityChange (SensitivityValue);
		}
		tempSensitivity = SensitivityValue;
	}
	

	void SensitivityChange (float sensitivityValue) {
		PlayerPrefs.SetFloat("Sensitivty", sensitivityValue);
		PlayerPrefs.Save ();
	}
}

I see no problems with your code.

But if you made your SensitivityChange function public. You could use it as the OnValueChanged callback in the ScrollBar inspector. Which would negate the use of your Update and tempSensitivity.