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 Commander Quackers · Dec 13, 2013 at 11:24 PM · fpssoundgunreload

Temporarily disable audio?

The title basically says it, but I'm making an FPS game and would like to know how to disable audio for a specific time, (for example, 3 seconds.) My FPS character can press the reload key (R) as many times as they want while it is reloading and the reload sound will play, so I need to find a way around this. Can anyone help with disabling audio temporarily (until the reload time passes) or some other way around this?

Side notes: - The reload function is called by pressing R - Once the reload is complete, the player can't reload again until either the bullets are less than a full clip, or they manually reload by pressing the R key.

(So basically the question is how can I play the audio only one time while it is reloading?)

Thanks in advance!

Comment
Add comment · Show 3
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 guitarxe · Dec 14, 2013 at 01:21 AM 0
Share

Can you provide a bit more details, and perhaps your code? From what I gathered, it seems like you have separate functions to do the reload and play the audio.

What's stopping you from having the audio be played from the same function as the reload? This way you can prevent the execution of the reload function until the reload is complete, thus no need to try and mute audio.

avatar image Commander Quackers · Dec 14, 2013 at 01:26 AM 0
Share

Well the problem is that while the player is reloading, they can keep calling the reload function (which lets them restart the reload sound over and over) until the reload is done

avatar image guitarxe · Dec 14, 2013 at 02:51 AM 0
Share

Yes, this is why I said prevent the execution of the reload function until reload completes. Surely you understand how to do this?

It's as simple as (pseudo-code)

 if(!reloadAnimationIsPlaying)
 {
  reloadAnimationIsPlaying = true;
  //do reload stuff
  reloadAnimationIsPlaying = false;
  
 }

1 Reply

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

Answer by jaj123 · Dec 14, 2013 at 12:55 AM

Something like this

 var reloadTime : float;
 var playing : boolean;
 
 function Update () {
 
 if (Input.GetButtonDown("Reload") && playing == false){
 Reload();
 }
 }
 
 function Reload() {
 playing = true;
 
 ///PlaySound
 
 yield WaitForSeconds (reloadTime);
 playing = false;
 }
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 Commander Quackers · Dec 14, 2013 at 03:19 AM 0
Share

Thank you, fixed the problem!

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

17 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

Related Questions

Some issues with weapon switching and reloading? 2 Answers

How to add sound to gun shot script 4 Answers

Reload Mobile 0 Answers

Invoke problem, can't manually reload 1 Answer

How to play a reload sound when "r" pressed and clip empty (Using Dastardly Banana's FPS Package) 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