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 /
  • Help Room /
avatar image
0
Question by Broccoliguy04 · Mar 30, 2018 at 01:15 AM · slider

Slider value help

So I am trying to change the value of a slider via script, but obviously, it's not working. In fact, it is only working for one of my three sliders. When I load the scene, only one of my sliders is set, while the other two remain at zero. Here are the associated scripts. If you need any more info, feel free to ask, and thank you in advance.

GameControl.cs

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 //for the music handeler, Singleton
 public class GameControl : MonoBehaviour {
     static public GameControl me;
     public AudioSource source;
     void Start () {
         source.volume = SavingLoading.hi.MusicVolume;
         if (me == null) {
             DontDestroyOnLoad (gameObject);
             me = this;
         } else if (me != null) {
             Destroy (gameObject);
             source = GetComponent<AudioSource> ();
         }
     }
     public void AdjustMasterVolume(Slider Mslider,Slider MuSlider, Slider SFXSlider){
         SavingLoading.hi.MasterVolume = Mslider.value;
         SavingLoading.hi.MusicVolume = MuSlider.value;
         SavingLoading.hi.SFXVolume = SFXSlider.value;
         source.volume = SavingLoading.hi.MusicVolume*SavingLoading.hi.MasterVolume*1.2f;
     }
     public void AdjustMusicVolume(Slider slider){
         SavingLoading.hi.MusicVolume = slider.value;
         source.volume = SavingLoading.hi.MusicVolume*SavingLoading.hi.MasterVolume*1.2f;
     }
     public void AdjustSFXVolume(Slider slider){
         SavingLoading.hi.SFXVolume = slider.value;
     }
 }

OptionsMenu.cs

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class OptionsMenu : MonoBehaviour {
     public Slider Master;
     public Slider Music;
     public Slider SFX;
     public AudioClip ping;
     public AudioSource source;
     void Start(){
         SavingLoading.hi.LoadVolume ();
         source = this.GetComponent<AudioSource> ();
         SetSliders ();
     }
     public void AdjustMasterVolume(){
         GameControl.me.AdjustMasterVolume (Master,Music,SFX);
     }
     public void AdjustMusicVolume(){
         GameControl.me.AdjustMusicVolume (Music);
         print (Music.value+" Music");
     }
     public void AdjustSFXVolume(){
         GameControl.me.AdjustSFXVolume (SFX);
         source.volume = SavingLoading.hi.SFXVolume*SavingLoading.hi.MasterVolume;
         source.Play();
         print (SFX.value + " SFX");
     }
     public void SaveVolume(){
         SavingLoading.hi.SaveVolume ();
     }
     void SetSliders(){
         Master.value = SavingLoading.hi.MasterVolume;
         Music.value = SavingLoading.hi.MusicVolume;
         SFX.value = SavingLoading.hi.SFXVolume;
         print (SavingLoading.hi.MusicVolume+" SL.h.MV");
         print (SavingLoading.hi.MasterVolume+" SL.h.M");
         print (Music.value+" Music");
         print (SFX.value + " SFX");
     }
     public void DeleteHS(){
         SavingLoading.hi.DeleteHS ();
     }
     public void DeleteAllData(){
         SavingLoading.hi.DeleteAllData ();
     }
 }

Part of PlayerController.cs

 public class PlayerController : MonoBehaviour {
     float speed;
     public Text countText;
     public Text winText;
     public AudioClip winSound;
     public AudioClip pingSound;
     public float colNum;
     private Rigidbody rb;
     private int count; 
     private AudioSource source;
     private AudioSource ping;
     //from here to next comment, controls the player
     void Start (){
         if (gameObject.CompareTag ("Lvl1")) {
             SavingLoading.hi.currentLevel = 1;
         } else if (gameObject.CompareTag ("Lvl2")) {
             SavingLoading.hi.currentLevel = 2;
         } else if (gameObject.CompareTag ("Lvl3")) {
             SavingLoading.hi.currentLevel = 3;
         } 
         SavingLoading.hi.SaveLvl ();
         print (SavingLoading.hi.currentLevel);
         speed = 10;
         rb = GetComponent<Rigidbody>();
         count = 0;
         SetCountText ();
         winText.text = "";
         ping = GetComponent<AudioSource > ();
         source = GetComponent<AudioSource> ();
         source.volume = SavingLoading.hi.SFXVolume*SavingLoading.hi.MasterVolume*1.8f;
         ping.volume = SavingLoading.hi.SFXVolume * SavingLoading.hi.MasterVolume*1.8f;
     }

Part of SavigLoading.cs

 public void SaveVolume(){
         BinaryFormatter bf = new BinaryFormatter();
         FileStream file = File.Create (Application.persistentDataPath + "/vol.data");
         Data vol = new Data ();
         vol.MasterVolume = MasterVolume;
         vol.MusicVolume = MusicVolume;
         vol.SFXVolume = SFXVolume;
         bf.Serialize (file, vol);
         file.Close ();
         print ("Saved vol!");
     }
     public void LoadVolume(){
         if (File.Exists (Application.persistentDataPath + "/vol.data")) {
             BinaryFormatter bf = new BinaryFormatter ();
             FileStream file = File.Open (Application.persistentDataPath + "/vol.data", FileMode.Open);
             Data vol = (Data)bf.Deserialize (file);
             MasterVolume = vol.MasterVolume;
             MusicVolume = vol.MusicVolume;
             SFXVolume = vol.SFXVolume;
             file.Close ();
             print ("Loaded");
     }

Once again, thank you in advance.

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

75 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

Related Questions

Change Value Of UI Light Slider to Read At Specific Points Of Slider Value 1 Answer

How do I apply a mask to a slider fill so it uses my quadrilateral design 0 Answers

Custom range/slider attribute with fields for min/max float variables, e.g. '[Range(myFloat0, myFloat1)]' 0 Answers

adjusting volume of music in a previous scene 0 Answers

Slider not disabling 1 Answer


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