Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 TSI25 · Dec 12, 2013 at 07:02 PM · menuonguivolumeunity4.3

Music Slider hookup?

I'm trying to make an options menu in which there is an audio slider that alters the volume level of the main menu. I've looked this up and it looks fool proof, I'm embarrassed that I can't get this but it must be something really simple. This is effectively how its rigged up right now, I'm using Javascript.

 #pragma strict
 var pauseText : String;
 var paused : boolean;
 var optioned : boolean;
 var volume : float;
 var musicSlider : float;
 
 function Start () {
     pauseText = "Pause";
     paused = false;
     optioned = false;
 
     volume = 100.0f;
     musicSlider = 100.0f;
 }
 
 function Update () {
 
     audio.volume = musicSlider;
 
 
     if (paused == true){
         Time.timeScale = 0;
         } else {
             Time.timeScale = 1;
             }    
             
 
 }
 
 function OnGUI () {
     if (GUI.Button (Rect (240,420, 70, 40), pauseText)) {
     paused = true;
     }
     
     //DEALS WITH THE MAIN PAUSE MENU
     if (paused == true){
     (GUI.Box (Rect (50,50, (Screen.width - 50), (Screen.height - 50)), (" ")));
         //This is the ONGUI code for the Options menu
         if (optioned == true){
         
             musicSlider = GUI.HorizontalSlider (Rect (((Screen.width * 0.5) - 50), ((Screen.height * 0.5) + 20), 100, 40), musicSlider, 1.0, 10.0);
                     
             if (GUI.Button (Rect (((Screen.width * 0.5) - 35),((Screen.height *0.5) - 100), 70, 40), "Menu")) {
                  Application.LoadLevel("StartScreen");
             }
             
             if (GUI.Button (Rect (((Screen.width * 0.5) - 35),((Screen.height *0.5) - 50), 70, 40), "Back")) {
                  optioned = false;
             }
         //This is the ONGUI code for the Main menu
         } else {
     
             if (GUI.Button (Rect (((Screen.width * 0.5) - 35),((Screen.height *0.5) - 100), 70, 40), "Menu")) {
                 Application.LoadLevel("StartScreen");
             }
             
             if (GUI.Button (Rect (((Screen.width * 0.5) - 35),((Screen.height *0.5) - 50), 70, 40), "Resume")) {
                 paused = false;
             }
             
             if (GUI.Button (Rect (((Screen.width * 0.5) - 35),((Screen.height *0.5)), 70, 40), "Options")) {
                 optioned = true;
             }
         }
     }
 }




Right now whats going on is that the audio kicks on at full blast (which is to be expected with how i set them to full in the beginning.) Hitting pause does pause the game, but moving adjusting the slider does nothing to effect the volume. In fact really everything that isn't the volume slider, and that has actually been implemented, functions as I expect it to. Do I need to call it differently in the update or ongui function?

Comment
Add comment · Show 2
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 fafase · Dec 12, 2013 at 07:23 PM 0
Share

Does it affect the musicSlider variable? Print it out to see if this one is changing.

avatar image TSI25 · Dec 12, 2013 at 07:27 PM 0
Share

Yes, i put a Debug.Log(musicSlider); in there and its bouncing healthily between the $$anonymous$$imum and maximum when i adjust the slider back and forth. Its just not getting applied to the actual audio for some reason....

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by TSI25 · Dec 12, 2013 at 08:36 PM

I figured it out!

i declare in this line

musicSlider = GUI.HorizontalSlider (Rect (((Screen.width 0.5) - 50), ((Screen.height 0.5) + 20), 100, 40), musicSlider, 1.0, 10.0);

that the music should toggle between 1.0 and 10.0. the volume can only actually be set to a value between 0.0 and 1.0 (i think... at least thats how it is in the editor.) Anyway i reset those values to 0.0 and 1.0 respectively and now it works like a charm.

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

16 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

Related Questions

boolean flicker 3 Answers

Pause Menu Volume 1 Answer

Alternate solution to onGUI for GUI? 4 Answers

Placing button at corner using NGUI 2 Answers

how the player control on volume in the game? 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