Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by gpuelston2004 · Mar 09, 2019 at 11:49 PM · uiplayerprefsslider

How to save slider values?

I was wondering if anyone had any way to save slider values i dont really have a script cause all the things i have tried will not work cause i cant import the slider into the actual reference box on the script and it will not let me directly find the slider in the script.

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image bpaynom · Mar 09, 2019 at 11:58 PM 0
Share

Share some code of what you tried, and some pics of the setup of the slider, so we can see what you did wrong and how to fix it.

avatar image gpuelston2004 · Mar 10, 2019 at 12:02 AM 0
Share

alt text

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class Slidersaver : $$anonymous$$onoBehaviour
 {
 
     public Slider xslider;
 
 
     void Start()
     {
        xslider = GameObject.Find("Slider").GetComponent<Slider>().value;
        xslider.value = PlayerPrefs.GetFloat("OptionScore");
 
     }
 
     void Update()
     {
         PlayerPrefs.SetFloat("OptionScore", xslider.value);
     
 
     }
 }
slider.png (193.1 kB)
avatar image bpaynom gpuelston2004 · Mar 10, 2019 at 12:29 AM 0
Share

You can actually save your slider values in your Slider.SetLevel(float value) function. Also, I dont know why you have Slidersaver class (what you share) and ins$$anonymous$$d your slider has attached SavingSlider which is another different class.

avatar image Hellium · Mar 10, 2019 at 12:29 AM 0
Share

Since your slider is public, you don't need to call Find, just drag & drop the gameObject holding the slider into the field. It's even more interesting since the script is on the same object as the slider itself.


If we forget this point, What does not work with your current script?

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by zereda-games · Mar 10, 2019 at 04:40 PM

 public class PlayerPrefsManager{

     const string MasterVolumeSaveKey ="Master Volume";
     public static float Volume;
     /// <summary>
     /// Gets the master volume.
     /// </summary>
     /// <returns>The master volume.</returns>
     public static float GetMasterVolume ()
     {
         Volume = PlayerPrefs.GetFloat (MasterVolumeSaveKey);
         return Volume;
     }

     /// <summary>
     /// Sets the master volume.
     /// </summary>
     /// <param name="value">Value.</param>
     public static void SetMasterVolume (float value)
     {
         if (value >= 0f && value <= 1f) {
             PlayerPrefs.SetFloat (MasterVolumeSaveKey, value);

         } else {
             Debug.LogException (new System.Exception ("Music volume slider out of range. Set slider between 0 and 1 and Not whole numbers."));
         }
     }
 }


to use:

 public Slider VolumeSlider;
 public static float volume;
 
 void Update(){
     volume = PlayerPrefsManager.GetMasterVolume("MasterVolume");
     OnChangeVolume(VolumeSlider.value);
 }

 void OnChangeVolume(float value){
     PlayerPrefsManager.SetMasterVolume("Master Volume",  VolumeSlider.value);
 }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image gpuelston2004 · Mar 15, 2019 at 05:01 PM 0
Share

@zereda-games Iv used this but after i reference the slider it wont let me drag my slider into the reference box on the script once in the manager is there a specific reason for this

avatar image
0

Answer by gpuelston2004 · Mar 10, 2019 at 12:34 AM

Okay thanks for the comments but the reason i have 2 different things calling the slider is because nither of the ways i tryed worked but thanks for thr help i will try that

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by DawdleDev · Mar 10, 2019 at 04:26 PM

Here's your problem. You never use Playerprefs.Save(). Try adding this to the script to make it save each time you load a new scene.

 private void OnDisable () {
         Playerprefs.Save ()
 }


Everything else here seems good to go.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

173 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

UI Slider, Save Values and Change Them 0 Answers

Slider won't slide, issue assigning PlayerPrefs and then changing the PlayerPrefs' value 1 Answer

Updating UISlider with value from variable. 1 Answer

How to lock a slider unless the handle is being interacted with? 0 Answers

How do i move the slider with GVR reticle pointer? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges