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 TheFrankman123 · Apr 24, 2012 at 03:06 PM · soundflashmute

Mute Button

Hello.

I am exporting to Flash and as a result you can't edit sound in script. So to work round this you have to turn an object with the sounds on it on and off rather than simply telling the volume to be 0 in script. So i have everything working in the below script. The issue i am having is that it doesn't remember that it's muted on the next level. Here is the code i am using. This code is on an empty game object called musicManager that turns a child object of the camera called music on and off depending on whether you have clicked the mute botton or not.

 var soundOn : boolean = true;
 var music : GameObject;
 var soundOnImg : Texture2D;
 var soundOffImg : Texture2D;
 
 function Awake () {
     
     DontDestroyOnLoad(this);
     
     if(soundOn == true) {
         
         music.active = true;
         
     }
 
 }
 
 function OnGUI () {
     
     if(soundOn == true) {
         if(GUI.Button(Rect(50, 0, 20, 20), soundOnImg)) {
             soundOn = false;
             music.active = false;
             //GUI.DrawTexture(Rect(50, 0, 20, 20), soundOnImg);
             
         }
         
     }
     
     if(soundOn == false) {
         if(GUI.Button(Rect(50,0,20,20), soundOffImg)) {    
             soundOn = true;
             music.active = true;
         }
     }
     
 }

So i have a dont destroy on load and the same set up of objects in the second level. If i don't have the if sound is true in the awake then when you start the game there is no sound playing until you click the button to the muted state and then again to play the sound. The issue is that when you start the next level this awake function is called again and therefore the music gameobject is set to true again. I realise this is hard to follow so if there is something you don't understand let me know.

Comment
Add comment · Show 1
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 TheFrankman123 · Apr 24, 2012 at 03:27 PM 0
Share

Basically... I need music to be set to active on awake but then for it not to call that awake function again in the next level...

1 Reply

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

Answer by TheFrankman123 · Apr 24, 2012 at 03:33 PM

Forget it, i was being dumb. During part of my testing i had disabled the music game object in the inspector, so when you started the game it wasn't playing until you clicked mute on the off again. So the final code is very much what is set as above in case it is useful to anyone but remember. THIS IS A VERY SHIT WAY TO DO IT. I am only doing it this way because Flash Export doesn't support editing sound in script.

 var soundOn : boolean = true;
 var music : GameObject;
 var soundOnImg : Texture2D;
 var soundOffImg : Texture2D;
 
 function Awake () {
     
     DontDestroyOnLoad(this);
  
 }
 
 function Update () {
 
     if(soundOn == true) {
         
         Debug.Log("sound is true");
         
     }
     
     if(soundOn == false) {
     
         Debug.Log("sound is false");    
         
     }    
     
 }
 function OnGUI () {
     
     if(soundOn == true) {
         if(GUI.Button(Rect(50, 0, 20, 20), soundOnImg)) {
             soundOn = false;
             music.active = false;
             
             
         }
         
     }
     
     if(soundOn == false) {
         if(GUI.Button(Rect(50,0,20,20), soundOffImg)) {    
             soundOn = true;
             music.active = true;
         }
     }
     
 }
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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

DontDestroyOnLoad level mute. 0 Answers

how do i mute all audio sound? 3 Answers

mute/un-mute 1 Answer

Mute/Unmute not working with new sounds 2 Answers

Mute/Unmute Sound For All Game Scenes by pressing Button 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