Author Topic: Saving slider Thumb location on reload?  (Read 4067 times)

Kristian

  • Guest
Saving slider Thumb location on reload?
« 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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Saving slider Thumb location on reload?
« Reply #1 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.

Kristian

  • Guest
Re: Saving slider Thumb location on reload?
« Reply #2 on: February 01, 2013, 03:57:03 AM »
This did not quite help me. mind explaining a little bit? :-\ , thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Saving slider Thumb location on reload?
« Reply #3 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. }