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
-1
Question by awplays49 · Jan 17, 2015 at 12:54 AM · multiplehowvolume

How would I have a volume bar in multiple places?

For example, at the menu, and at the pause menu... How?

Comment
Add comment · Show 5
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 Simon-Larsen · Jan 17, 2015 at 01:00 AM 0
Share

What exactly do you mean by how? Do you mean how to synchronize the value between the two volume bars?

avatar image Superrodan · Jan 17, 2015 at 01:01 AM 0
Share

Do you already have the volume bar created and are just trying to get two different ones working together? Or are you also asking how to make a volume bar in general?

avatar image awplays49 · Jan 17, 2015 at 01:02 AM 0
Share

As in what code would make it so these happen

You are at the menu

you change the volume and it affects the audio

the volume bar now = the menu volume bar

AND VICE VERSA for the pause menu

avatar image awplays49 · Jan 17, 2015 at 01:02 AM 0
Share

@Superrodan I have one at the menu

avatar image Simon-Larsen · Jan 17, 2015 at 01:07 AM 0
Share

You should look into playerprefs. This way you can also save the volume between sessions. http://docs.unity3d.com/ScriptReference/PlayerPrefs.html

1 Reply

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

Answer by Superrodan · Jan 17, 2015 at 01:08 AM

The way to do this is to have a variable you store somewhere globally. I did this with a playerprefs variable so that if I turned off the game and came back it would remember the volume I wanted.

So whenever they change the volume you determine what they changed it to and run this code:

     PlayerPrefs.SetFloat("Volume", 0.75F);

The 0.75f in the above example would be whatever float they changed the volume to.

Additionally, whenever you load any screen with a volume bar on it you run this code:

     float tempVolume =  PlayerPrefs.GetFloat("Volume", 1.0F);

Instead of 1.0f in the above code you would put whatever you want the default volume to be. This code will return the volume that they set last time OR it will return the default volume if they have never set a volume.

Once you have run that code you just set your volume bar to the value of tempVolume.

Comment
Add comment · Show 4 · 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 awplays49 · Jan 17, 2015 at 01:09 AM 0
Share

does this work if the volume bars are in different scenes?

avatar image Superrodan · Jan 17, 2015 at 01:11 AM 0
Share

Yes. PlayerPrefs is stored externally. It basically writes it to a file somewhere on the device and pulls it from that file later.

PlayerPrefs is useful for saving things across scenes AND game sessions. With this code if you turn off the game and turn it back on it will remember what the volume was last time.

avatar image awplays49 · Jan 17, 2015 at 01:23 AM 0
Share

thanks! :)

avatar image Superrodan · Jan 17, 2015 at 01:28 AM 0
Share

No problem. Don't forget that you also need to set the actual volume of your sound to the same variable.

Otherwise your volume bars will remember what the player set the volume to but the sound itself will not.

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

27 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

Related Questions

Trouble with apply damage to enemy 2 Answers

How to detect range of multiple gameobjects? 1 Answer

Draw multiple sprites with 1 GameObject 0 Answers

Crossfade between multiple loops with 3 audioSources ? 0 Answers

How to change Audio Importer settings for multiple files? 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