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 Peanut97 · Nov 17, 2013 at 10:32 PM · audiomusickey

Can anyone help me invert this simple script?

Good Afternoon,

I am currently attempting to work with music. In my scene, I have a Player and an Empty GameObject with an audio source attached to it. The audio source has the following script attached to it:

     function Update() {
          if(Input.GetKeyDown(KeyCode.Escape)) {
              if(audio.mute)
                 audio.mute = false;
             else
                 audio.mute = true;
         }
     }

This script works perfectly, but the opposite way I want it to. The music from the audio source begins to play right when I start the scene and toggles on and off whenever I hit the Escape Key. I need the audio to not start UNTIL I hit the Escape Key and then toggle on and off after that. If anybody could help me out with modifying this script, I would really appreciate!! Thank you so much!!

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 AeonIxion · Nov 17, 2013 at 11:08 PM 0
Share

Btw if you use audio.mute, the song will continue playing even if it's muted. So even if you set audio.mute to true at the beginning, the audio will still start playing, you just won't hear it. If you want to actually pause and continue playing the audio use audio.isPlaying, audio.Play and audio.Pause

2 Replies

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

Answer by Tomer-Barkan · Nov 18, 2013 at 07:57 AM

Just initialize the mute as true, and then whenever escape is pressed, switch it:

 function Start() {
     aduio.mute = true;
 }

 function Update() {
     if(Input.GetKeyDown(KeyCode.Escape)) {
         audio.mute = !audio.mute;
     }
 }
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
avatar image
0

Answer by pvpoodle · Nov 17, 2013 at 10:39 PM

does audio.mute = true; set the audio to mute? which is what i assume it does.

have you tried setting audio.mute in the start or awake functions?

 function Start() {
 audio.mute = true;
 }

if that doesnt work you could also try

 function Update() {
 
 audio.mute = true;
 
 if(Input.GetKeyDown(KeyCode.Escape)) {
 if(audio.mute)
 audio.mute = false;
 else
 audio.mute = true;
 }
 }
Comment
Add comment · Show 6 · 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 Peanut97 · Nov 17, 2013 at 10:40 PM 0
Share

Thanks so much for your help! I'll go give that a try really quick.

avatar image AeonIxion · Nov 17, 2013 at 10:44 PM 0
Share

You can also just check the checkbox behind 'mute' on the audio source component. This will start the scene with audio muted.

avatar image Peanut97 · Nov 17, 2013 at 10:44 PM 0
Share

I just gave that second script a try and it didn't seem to work. It did check the mute box, but it didn't "unmute" when I pressed escape. The script I currently have does not "mute" the audio source. I tried look for the parameter it is adjusting and I can't seem to find it. Any ideas?

avatar image Peanut97 · Nov 17, 2013 at 10:55 PM 0
Share

It tried to start the scene with the mute button pressed and that didn't work either. I just don't understand what's going on. It should be working.

avatar image pvpoodle · Nov 17, 2013 at 10:59 PM 0
Share

can you please explain a bit further on where exactly and how exactly you are planing on using this script?

Show more comments

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

20 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

Related Questions

Multiple Cars not working 1 Answer

dynamic audio measuring? 0 Answers

Unity Unable to Reassign Audio Clip 1 Answer

Stop another sound from another script? 1 Answer

Get acess and switch to many audio source in a single Object HELP!! 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