Author Topic: Slider value Start() interfering with setting from PlayerPrefs?  (Read 4240 times)

Majicpanda

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
I have two UISliders for music and volume.  OnSliderChange for each accurately changes the PlayerPref value for each and is clearly stored and saved after much testing.  When I run the game it appears that OnSliderChange is automatically called for each slider to initialize them to whatever you have set in the editor, and this occurs in Start() making me not understand how to use my UIManager singleton to update the sliders since Start() in my manager fires before (sometimes after, Unity..) the initial slider init fires.

Not sure what I'm missing but I can't see what order to execute code to be able to read player prefs in and set each..

  1.         void Start () {        
  2.                 MusicSlider.sliderValue = GameManager.Instance.playerData["Player"].musicVolume;
  3.                 SoundSlider.sliderValue = GameManager.Instance.playerData["Player"].soundVolume;                       
  4.         }
  5.  

Majicpanda

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
Re: Slider value Start() interfering with setting from PlayerPrefs?
« Reply #1 on: May 12, 2013, 05:58:28 PM »
Been a really long day... I simply put my script in Awake() instead of Start() and the NGUI Start() takes on the sliderValue that I set in Awake() so it gave me the intended results.

Is this the correct way?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Slider value Start() interfering with setting from PlayerPrefs?
« Reply #2 on: May 13, 2013, 01:23:41 AM »
Yup.