Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 DevSkeletal · Oct 08, 2015 at 01:42 AM · cameraaudiosoundsound-overlapping

how to have multiple game objects play a single looping sound

Il try and explain this as best i can, working in unty5, 2d, c#

i have these fires as hazards, they make a sound which is just a looping fire sound, they only play when the camera is on screen though, this is managed through a script attached to the fires which detects when the camera is onscreen, however if you have a bunch of these things and theyre all on screen the sort of double over one another as each of them is playing the sound at the same time

Ive had this issue before so i have an audio master set up to play certain sounds via a script, like my moving spike scripts which would all go up the same time, however these were for sounds that only played once

the problem im trying to figure out is how to have these fire platforms play a sound in the audio manager but only when at least one of them is on screen, and since im working with boolians when a single fire platform leaves the screen and se the bool the off, the ones on the screen set the bool back to on, resulting in the sound starting from the beggining infinatley, as they are now it only sounds normal if they are all off the screen or all on the screen

any ideas? would really appreciate any ideas around this problem

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 AngryMuppet · Oct 08, 2015 at 08:16 AM 0
Share

Are you bothered about positional tracking of the SFX or is it more just a general 'ambiance track' there are a couple of methods you could use depending on the effect you're looking for?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by NDark · Oct 08, 2015 at 10:19 AM

You should not use Boolean but use integer to record the status of sound on/off.

As long as "the number of fire on the screen" is set from 0 to a number larger than 0, active play. Pause sound when the number goes down to 0 from a positive number.

If I were you, I will

  1. Add a static script to record the number of fire on the screen

  2. Add a script on the fire to detect this fire just enters the screen or goes out of the screen.,

  3. Add a audio source to play this sound. Use the static script above to control this audio source.

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 HarshadK · Oct 08, 2015 at 08:41 AM

Just keep a counter of how many fires are there being shown on screen and continue playing sound only if there is at least one fire on the screen. You can then update this counter when fire arrives on or leaves the screen.

Psuedo code Just to give you an idea, it's neither accurate nor complete.

Audio Manager:

 static int firesOnScreen = 0;
 
 void Update()
 {
     if(firesOnScreen > 0)
     {
         // Play sound only if it was not already playing otherwise just let it play.
         if(!soundisPlaying)
         {
             PlaySound();
         }
     } else
    {
         if(soundisPlaying)
         {
               StopSound();
         }
      }
 
     public void FireCameOnScreen()
     {
         firesOnScreen++;
     }
     public void FireLeftScreen()
     {
         firesOnScreen--;
      }
 }

Now you can access these FireCameOnScreen() and FireLeftScreen() methods as you were using your boolean.

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 DevSkeletal · Oct 08, 2015 at 07:52 PM 0
Share

Thats really helpful thank you, id considered using integers but not atempted it, thank you very much for your help, il test it out

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How would I reference the end of audio? 0 Answers

Play from a variety of sounds? 1 Answer

Sounds are shaky at high speed. 0 Answers

5.1 Channels is backwards in unity (non 3D) 0 Answers

Audio Settings Menu 2 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