Author Topic: Slider Value not change from PlayerPrefs...  (Read 14636 times)

faceOFF

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Slider Value not change from PlayerPrefs...
« on: August 22, 2012, 06:32:53 AM »
Why AudioListener.volume - it remember fine, but Slider Value not  ???  ?

  1. using UnityEngine;
  2. using System.Collections;
  3. using System.IO;
  4.  
  5.  
  6. public class onSliderChange : MonoBehaviour
  7. {
  8.         public GameObject slider;
  9.        
  10.         void Start (float volume)
  11.         {
  12.                 AudioListener.volume = PlayerPrefs.GetFloat("Sound");
  13.                 volume = PlayerPrefs.GetFloat("Sound");
  14.         }
  15.        
  16.        
  17.     void OnSliderChange (float volume)
  18.     {
  19.                 // AudioListener.volume = volume;
  20.                 AudioListener.volume = PlayerPrefs.GetFloat("Sound");
  21.                 PlayerPrefs.SetFloat("Sound", volume);
  22.                 PlayerPrefs.Save();
  23.     }
  24. }

faceOFF

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: Slider Value not change from PlayerPrefs...
« Reply #1 on: August 22, 2012, 07:50:06 AM »
ArenMook, can you tell how to consider the Slider Value of PlayerPrefs?
This is not the case when the "... need to know the basic Unity 3d and basic C #",
it's yours UISlider.cs?

PhilipC

  • Guest
Re: Slider Value not change from PlayerPrefs...
« Reply #2 on: August 22, 2012, 10:20:08 AM »
I'm really lost as to what you are trying to do. Lets break down the code you posted....

public class onSliderChange : MonoBehaviour
{
    public GameObject slider; <----- This is never used. is this a reference to the slider that you want to change? if so why are you not using UISlider instead of GameObject
   
    void Start (float volume) <---- What is calling this start method? Having the parameter means Unity wont be calling it.
    {
        AudioListener.volume = PlayerPrefs.GetFloat("Sound");
        volume = PlayerPrefs.GetFloat("Sound"); <-------You are setting the method parameter volume which will do nothing.
    }
   
   
    void OnSliderChange (float volume)
    {
        // AudioListener.volume = volume;
        AudioListener.volume = PlayerPrefs.GetFloat("Sound"); <--- You are setting the listener volume to be the last saved value
        PlayerPrefs.SetFloat("Sound", volume); <--- You are then saving the new value. If anything these would need to switch
        PlayerPrefs.Save();
    }
}

Try looking at UISoundVolume i think it does more of what you want because i dont see this code working at all...

If you want to use playerprefs instead of NGUITools.soundVolume go right ahead. Although i would recommend not writing to player prefs every time the slider moves as its not a "cheap" operation to do. Its better to save it once when you leave the "settings" menu

faceOFF

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: Slider Value not change from PlayerPrefs...
« Reply #3 on: August 22, 2012, 08:06:29 PM »
What nonsense!? This code works fine!
Check! No errors!

  1. using UnityEngine;
  2. using System.Collections;
  3. using System.IO;
  4.  
  5.  
  6. public class onSliderChange : MonoBehaviour
  7. {
  8.     void OnSliderChange (float volume)
  9.     {
  10.                 AudioListener.volume = PlayerPrefs.GetFloat("Sound");
  11.                 PlayerPrefs.SetFloat("Sound", volume);
  12.                 PlayerPrefs.Save();
  13.     }
  14. }


And me don't need to tell what is right and what not!
The code does what it should do!
Those controls the volume and stores it in PlayerPrefs!

I repeat the question:
HOW TO KEEP YOURS! IMPORTANCE "VALUE" (slider in the Inspector) in PlayerPrefs?!

faceOFF

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: Slider Value not change from PlayerPrefs...
« Reply #4 on: August 22, 2012, 09:53:09 PM »
Instead of what would normally be explained, you got me confused!
Understood ... took the script and added string in UISoundVolume.cs!
Now it works! I will write here that would not mislead people,
as you do! Rather than do their job support!

Here is the working code that changes sound volume in the game and remembers the value after quit!

Support - learn! That's how you should do your job!
Now I do it instead of you!
  1. using UnityEngine;
  2.  
  3. [RequireComponent(typeof(UISlider))]
  4. [AddComponentMenu("NGUI/Interaction/Sound Volume")]
  5. public class UISoundVolumeEd : MonoBehaviour
  6. {
  7.         UISlider mSlider;
  8.  
  9.         void Awake ()
  10.         {
  11.                 mSlider = GetComponent<UISlider>();
  12.                 mSlider.sliderValue = NGUITools.soundVolume;
  13.                 mSlider.eventReceiver = gameObject;
  14.         }
  15.  
  16.         void OnSliderChange (float val)
  17.         {
  18.                 NGUITools.soundVolume = val;
  19.                 AudioListener.volume = val;
  20.         }
  21. }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Slider Value not change from PlayerPrefs...
« Reply #5 on: August 22, 2012, 11:15:22 PM »
Judging from your code, you were confused long before you asked the question. Phil's inquiries into your code were valid. He was simply trying to figure out what you were trying to do so that he can help you. No need to get upset.

faceOFF

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: Slider Value not change from PlayerPrefs...
« Reply #6 on: August 22, 2012, 11:37:01 PM »
Judging from your answers, you again are trying on simple questions give to complex and confusing answers! I gave the my code (my experiments) not for the critics and the teachings, but make it clearer what I want! You have not understood what I wanted!? I'm upset only quality support, and the fact that I bought NGUI, no more ..
I showed you above how need to answer the questions!
Clear and understandable answer for everyone! I paid the money and want the plugins to work!
If I knew perfectly programming, I would don't ask questions and don't buy NGUI! I would write own GUI!
Think about it before you "try to help" better to just help;)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Slider Value not change from PlayerPrefs...
« Reply #7 on: August 23, 2012, 01:56:05 AM »
В следующий раз просто спроси по русски, нам обоим легче будет.

faceOFF

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: Slider Value not change from PlayerPrefs...
« Reply #8 on: August 23, 2012, 02:10:19 AM »
О, наши "в городе")) Я не знал что продукт русский))Некогда было разбираться кто есть кто... Хорошо что просветил!
Лады, тогда ответь, в ветке про Need UISavedPopup.cs something as for UISavedOption.cs! Пожалуйста ;)

mikechurch

  • Guest
Re: Slider Value not change from PlayerPrefs...
« Reply #9 on: May 25, 2013, 02:48:19 AM »
I know this is like 9 months after the fact, but...

I was hoping there were some insults traded in Russian, but sadly no.  It was very polite.

I want to make a point here.

For those of you who actually BOUGHT this awesome product, Aren's responses have been very patient, and way better than most people supporting their products.  I search here after I've read the FAQs and after I have tried many things.  Then I know what I'm looking for and get right to the answer.  I've had lots of small little problems with NGUI, but mostly of my own design.  Sometimes because I was lazy and cut/pasted code/prefabs without looking carefully at it.

Last thing I was looking for was a mistake on my part clearly because I couldn't get the answer here.  It turns out I had to recreate the 2D GUI root then moved my stuff from the old one over to the new one (then delete the old one).  I've had to do this three times, now.  Not sure why.  But my point is this:

It's not his job to answer every question and supply example code.  If you're asking questions about coding because you have minimal coding knowledge, learn to code better or ask someone else to do it.  Stretch your skills and try to understand what's going on - it will pay off a lot.  Precisely BECAUSE I had to look at the code (not all of it, just portions - mostly the API and the examples) - I realized how beautifully small all the little pieces are.  This makes them understandable, and modular, like lego bricks.

I have rewritten many pieces of my old and new code bits to be small and decoupled as possible so they can be reused elsewhere, even inside the same project.  Thanks, Aren.  Suddenly I understand what I'm doing and it reads like a book now.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Slider Value not change from PlayerPrefs...
« Reply #10 on: May 25, 2013, 08:50:24 PM »
I try to be polite because I know how frustrating learning something new can be... It sucks, it's scary, and there are a lot of unknowns and pitfalls in every new product. But I have to say this:

Doing support sucks more. It sucks giant hairy donkey nuts. I'm a developer, and I like creating new and exciting things, not spend years supporting something I've created long ago... and sometimes it's difficult for me to keep my cool and I am often tempted to reply with "wtf are you doing noob?" -- and in some posts it shows, I'm sure.

But then there are other times someone gets in touch with me or makes a post saying that my code has helped them learn or become a better developer... and those are the times I try to focus on at the end of the day -- because they are the ones that make it all seem worthwhile.

And so to you I say this:

Thank you.