Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Kristian on January 31, 2013, 09:01:06 AM

Title: Saving slider Thumb location on reload?
Post by: Kristian on January 31, 2013, 09:01:06 AM
Hi, I am trying to save the location of a slider thumb in Scene 1. and when I come back to Scene 1 I would like it to be on the same location.

How could i achieve this?

thanks.
Title: Re: Saving slider Thumb location on reload?
Post by: ArenMook on February 01, 2013, 01:04:07 AM
Write a script that will set the slider's value in Awake() and attach it to your slider.
Title: Re: Saving slider Thumb location on reload?
Post by: Kristian on February 01, 2013, 03:57:03 AM
This did not quite help me. mind explaining a little bit? :-\ , thanks
Title: Re: Saving slider Thumb location on reload?
Post by: ArenMook on February 01, 2013, 09:37:19 AM
  1. using UnityEngine;
  2.  
  3. [RequireComponent(typeof(UISlider))]
  4. public class SavedSlider : MonoBehaviour
  5. {
  6.         public string key = "My Slider";
  7.  
  8.         UISlider mSlider;
  9.  
  10.         void Awake ()
  11.         {
  12.                 mSlider = GetComponent<UISlider>();
  13.                 mSlider.sliderValue = PlayerPrefs.GetFloat(key, 0f);
  14.                 mSlider.onValueChange = OnSliderChange;
  15.         }
  16.  
  17.         void OnSliderChange (float val)
  18.         {
  19.                 PlayerPrefs.SetFloat(key, val);
  20.         }
  21. }