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 /
This question was closed Aug 25, 2014 at 03:53 PM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by caleb_b · Aug 25, 2014 at 01:48 AM · c#menupausevolumehorizontal-slider

Trying to make sliding volume bars.

Desired end result: A button in a pause menu labeled Settings or something like that. When that button is clicked, it opens to two slider bars, one controlling the background music's volume, the other controlling the sound effect's volume.

But for now, I'm just trying to get a slider bar to appear, and I'm not having much luck. This is the script thus far.

 using UnityEngine;
 using System.Collections;
  
 public class Menu : MonoBehaviour 
 {
  
     public bool gameIsPaused = false;
     public bool buttons = true;
 
     private float hSliderValue = 0.0f;
  
     void Update()
     {
         if(Input.GetKeyUp(KeyCode.P))
         {
             if(gameIsPaused)
             {
                 gameIsPaused = false;
                 Time.timeScale = 1.0f;
                 audio.Play();
             } else 
             {
                 gameIsPaused = true;
                     Time.timeScale = 0.0f;
                 audio.Pause();
             }
         }
     }
  
     void OnGUI()
     {
         if(gameIsPaused) 
         {
             if(buttons)
             {
                 if(GUI.Button(new Rect(Screen.width / 2 - 100, Screen.height / 2 - 75, 200, 50), "Resume"))
                 {
                     gameIsPaused = false;
                     Time.timeScale = 1.0f;
                 }
 
                 if(GUI.Button(new Rect(Screen.width / 2 - 100, Screen.height / 2 - -25, 200, 50), "Settings"))
                 {
                     buttons = false;
                 }
                 if(GUI.Button(new Rect(Screen.width / 2 - 100, Screen.height / 2 - -125, 200, 50), "Main Menu"))
                 {
                     Application.LoadLevel("MainMenu2");
                 }
 
             }
 
             if(buttons == false) 
             {
                 if(GUI.Button(new Rect(Screen.width / 2 - 100, Screen.height / 2 - -25, 200, 50), "Back"))
                 {
                     buttons = true;
                     hSliderValue = GUI.HorizontalSlider (new Rect (25, 25, 100, 30), hSliderValue, 0.0f, 10.0f);
                 }
             }
         }
     }
 }

With this code, I click the Settings button after pausing the game, and the Resume, Exit and Settings buttons dissappear, replaced by a Back button. But no slider. I copy and pasted the slider code from here (http://docs.unity3d.com/Manual/gui-Controls.html) in case the reader wonders why the code for positioning the slider is different from the code positioning the buttons. Can anyone tell me why the slider is not appearing? And how I can fix it?

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

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by Tomer-Barkan · Aug 25, 2014 at 03:48 AM

You put your slider code in the wrong position. You put it inside the if(back) scope, which means it will only be displayed when you click back button (and only for 1 frame).

Remove it outside the if and it should work:

 if(buttons == false)
 {
     if(GUI.Button(new Rect(Screen.width / 2 - 100, Screen.height / 2 - -25, 200, 50), "Back"))
     {
         buttons = true;
     }

     hSliderValue = GUI.HorizontalSlider (new Rect (25, 25, 100, 30), hSliderValue, 0.0f, 10.0f);
 }
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 caleb_b · Aug 25, 2014 at 03:50 PM 0
Share

Exactly right. Thanks man.

Follow this Question

Answers Answers and Comments

23 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

Related Questions

Pause Menu Volume 1 Answer

Pause Menu Not Pausing 3 Answers

Unable to click UI Button (Unity 4.6) when TimeScale is 0 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 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