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 ryanconway · Aug 16, 2013 at 03:04 PM · soundplaysimultaneously

How to play two sounds at once on same object

I have 3 audio sources on my lantern object, each one has the different sound in, and then i have my script file which is below. When i turn the lantern on it only plays the burning sound and not the SoundTurnOn as well?

 var soundTurnOn : AudioClip;
 var soundTurnOff : AudioClip;
 var burning : AudioClip;
 var toggle : System.Boolean;
 
 function Start() {
 
  audio.clip = burning;
          audio.Play();
          
          }
  
 function Update() {
     if (Input.GetKeyDown(KeyCode.F)) {
         toggle = !toggle;
         
  
         if (toggle) 
         {
  audio.clip = soundTurnOff;
                audio.Play();
                 }
         else
         {
               burningfunction ();
            }
            }
            }
            
            function burningfunction () {
            audio.clip = soundTurnOn;
               audio.Play();
          audio.clip = burning;
          audio.Play();
          }
          
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 jacobschellenberg · Aug 16, 2013 at 04:23 PM 0
Share

I'd like to know this too. Bump.

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by Booperkit · Oct 05, 2015 at 05:52 PM

It is possible to have multiple audio sources on one game object.alt text


screenshot-2015-10-05-124053.png (151.0 kB)
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
1

Answer by zombience · Aug 16, 2013 at 04:31 PM

GameObjects may only have one audio source, and each audio source may only play one clip at a time. If you want to achieve multiple sounds, you may do something like:

create a prefab of an empty game object with nothing on it but an audiosource.

instantiate it in your script, assign the clip you'd like to play, and make it a child of your current gameobject (so it's location will follow your game object).

start playing both audiosources.

This is how I've done it in the past. Again, it is not possible to play multiple clips simultaneously from one audio source, and it is not possible to have mutliple audio sources on one game object

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 Umai · Dec 24, 2014 at 09:46 AM 0
Share

Read through this http://answers.unity3d.com/questions/11314/audio-or-music-to-continue-playing-between-scene-c.html and then my follow up question; what if we add like 10 child game objects to that singleton game object; could we then use 10 audio sources simultaneously throughout our game?

avatar image Pharan · Oct 05, 2015 at 06:35 PM 0
Share

The above answer is old. I'm not sure if it was correct back then either. $$anonymous$$ultiple AudioSource components on one GameObject do work just fine.

avatar image zombience · Oct 05, 2015 at 07:58 PM -1
Share

@Pharan you're right, it is possible to add more than one per game object. I created this answer way back when I was first learning unity and didn't know better.

Now that I've gotten to know a little more, though, unless you have a special use case, I wouldn't really recommend putting multiple audio sources on one game object. It would be harder to manage if you're assigning clips in the inspector, and I wouldn't necessarily trust that they were being returned in order top down from GetComponents. You would also not be able to separate audio sources by audio channel (in unity 5), and they'd all be constrained to one channel in the audio mixer.

You also wouldn't be able to fade in between clips if these are looping or longer audio clips. Fades would have to be baked into each audio clip. Perhaps one useful scenario for this might be a bomb prefab that had several layers of audio that could all be run at once, and be destroyed at the same time... but if you're going to do that, it's more efficient to bake all of those into one audio file.

So, it's technically possible to put multiple audio sources on one game object, but I'm not really sure why you'd want to do that in most cases.

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

19 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

Related Questions

Audio Playing upon death 1 Answer

How to Play a Sound from an Array from an Overloaded Method? 1 Answer

gameObject to play sound on deletion, won't work... 1 Answer

audio trigger keydown 1 Answer

How To play sound with a keypress 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