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 gamebalance · May 18, 2018 at 02:23 PM · sound

The simple way to put sounds in a game?

Hello,

What is the simple way to play sounds in game? Without any extras. We also need that the same sound would play only a single instance. For example, if there are 10 bombs exploded simultaneously we don't want there to be 10 explosion sounds played at once. Only single. So if the sound is the same then it should interrupt all previous sounds of the same type.

My coder don't know English much and he found some sound mixer and put into the game. I afraid it will eat extra CPU. We need just simply sounds playing without compression, limiter, multiple channels and stuff like that.

Thanks

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 TreyH · May 18, 2018 at 04:10 PM 0
Share

You're asking two questions:
1- How do I use sounds in the game
2- How do I implement some sort of load balancing for sound effects

Implementing sound effects is a straightforward exercise that I doubt will take you or your engineer any time, so we can skip that. It helps to read the documentation, though.

Load balancing sounds is a little more interesting and there are a few ways to go about it.

While you want multiple sounds to only play once (which smells a little like premature optimization), your players might not expect it. If you see 10 bombs about to explode on screen, then you sort of expect that a louder sound will happen versus just 1 bomb.

avatar image gamebalance TreyH · May 18, 2018 at 04:50 PM 0
Share

Our game can be compared to something like match 3 games(single screen casual tile based game). So it is better to have a single bomb sound even if there are 10 of them exploding at the same time.

avatar image gamebalance TreyH · May 18, 2018 at 04:55 PM 0
Share

The problem is that I am not into coding so I do not know what to look. And coder is bad with English. That's why I asked if there is some light on CPU option.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ImpOfThePerverse · May 18, 2018 at 03:50 PM

I'd write a singleton that lets your bombs get ahold of a single collection of audio sources, all set to 2D sound. You'd have one gameobject with a number of child audiosources, one for each sound effect. Leave the audio source spatial blend set to 2D since the audiosource location won't match up with the bombs, etc.

One really good reason to output to a mixer is that it lets you have a volume slider in your options menu that controls all audio sources at once.

 public class AudioManager : Monobehavior
 {
     public AudioSource sfxBombExplosion;
     public AudioSource sfxGunshot;
     // etc., one for each sound in your game
    
     private static AudioManager Instance { get; set; }
 
     void Awake()
     {
         if (Instance != null && Instance != this)
         {
             GameObject.Destroy(Instance.gameObject);
         }
         Instance = this;
     }
 
     public static void PlayBombExplosion() { Instance.sfxBombExplosion.Play(); }
 
     public static void PlayGunshot() { Instance.sfxGunshot.Play(); }
     // etc., one for each sound effect
 }

To play a sound effect:

 AudioManager.PlayBombExplosion();
Comment
Add comment · Show 3 · 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 gamebalance · May 18, 2018 at 04:57 PM 0
Share

I just worry about CPU that the mixer might use. The game should be crossplatform. It would be on mobile too. So it could be nice to use CPU optimal option. If mixer makes extra usage, that would not be good for mobiles. But if there is no difference or very little, then I would use it.

avatar image Oliver1135 gamebalance · May 18, 2018 at 05:08 PM 0
Share

It should be possible to remove the mixer/disable sound in some way and allow the game to still run with extremely $$anonymous$$or changes, what do you see when you profile it running vs disabled, i would be very interested to know the result.

avatar image gamebalance Oliver1135 · May 18, 2018 at 05:09 PM 0
Share

I will tell coder to try that. Good idea.

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

86 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Sound gets loud in while playing game? 1 Answer

How to activate a sound when a player walks through a collider 1 Answer

3d Sound not working? 0 Answers

how to add a sound when collecting coins? 0 Answers

Can i change tha audio driver? 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