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 hanaharu7 · Sep 28, 2012 at 06:14 AM · savesavingvolume

saving volume between scenes

I have a menu with a slider set up so I can adjust the volume. Although it works for my volume screen scene, it doesn't work in any other scene. I think I need to store the hsliderValue but I'm not even sure TBH. would really appreciate an assist.

 var backButton : Texture2D;
 var backRollover : Texture2D;
 var mouseEnterSound : AudioClip; 
 var mouseExitSound : AudioClip; 
 var hSliderValue : float = 0.5;
 private var correctedMousePosition : Vector2;
 private var mouseOver = false; // current mouse status
 private var isOver = false; // used to check status change
 
 
 function CheckButton(r: Rect, texOver: Texture2D, texOut: Texture2D): boolean {
     if ( r.Contains(correctedMousePosition) ) // if mouse over the button...
     {
         GUI.DrawTexture( r, texOver ); // draw the over texture...
         isOver = true;  // set isOver flag...
         return Input.GetMouseButtonUp(0); // and return mouse up status
     }
     else
     {
         GUI.DrawTexture( r, texOut ); // otherwise draw regular texture...
          return false; // and return false
     }
 }
 
 function OnGUI ()
 {
     correctedMousePosition = Vector2 (Input.mousePosition.x, (Screen.height-Input.mousePosition.y) );
     isOver = false; // prepare mouse enter/exit detection
     
     hSliderValue = GUI.HorizontalSlider(Rect(300,180,200,20), hSliderValue, 0.0, 1.0);
     GUI.Label(Rect(300,195,200,20), "Music="+hSliderValue);
     audio.volume = hSliderValue;
     
     if ( CheckButton( Rect(250,250,200,50), backRollover, backButton) )
     {
         Application.LoadLevel(1);
     }
     if (isOver != mouseOver){ // if mouse entered or exited button...
         mouseOver = isOver;   // update mouseOver and play appropriate sound
         if (mouseOver){
             audio.PlayOneShot(mouseEnterSound);
         } else {
             audio.PlayOneShot(mouseExitSound);
         }  
     }
 }
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

2 Replies

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

Answer by Sundar · Sep 28, 2012 at 04:30 PM

You need a script that stay alive through out game play say "PlayerSettings"

  1. Inside "PlayerSettings" call DontDestroyOnLoad(this) in Start() or Awake()

  2. add volume variable to store its value from slider and set its value.

  3. attach "PlayerSettings" to an empty gameobject

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 hanaharu7 · Sep 29, 2012 at 03:39 AM 0
Share

$$anonymous$$any thanks good sir!!!!

avatar image
0

Answer by rokyed · Sep 29, 2012 at 07:21 AM

or you can use this :

PlayerPrefs.SetInt("volume", 10); // this is an int

PlayerPrefs.SetFloat("volume", 10.0); // this is a float

// and then just call it like this :

myScriptVolume =PlayerPrefs.GetInt("volume"); //to get the int

myScriptVolume =PlayerPrefs.GetFloat("volume"); // to get the float

// note this will save also the value if you close the unity game , and store it forever untill you vant to erase it if you want and here is the code:

PlayerPrefs.DeleteKey("volume");

or just delete all

PlayerPrefs.DeleteAll();

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 aeronav1 · May 16, 2017 at 05:43 PM 0
Share

what is "volume" string represent?

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

12 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

Related Questions

Saving problem unity project 5 Answers

Save works for computer but not once i create the build and load it on the android 1 Answer

How do I make a basic easy Save and load function with JavaScript 1 Answer

Advice about saving complex data (Minecraft-like game) 1 Answer

Saving state across the scene シーンをまたぐ状態の保存 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