• 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 uanmanarmy · Apr 24, 2014 at 09:23 PM · audioaudiosourceaudio clippingaudio priority

Play audio clip on more than one object from another gameobject

Hey guys/girls.

I want to play a audio file on more than one gameObjects(with audioSource attached to them)

I am creating an empty object and attaching this script

 public class AudioPlayScript : MonoBehaviour {
 
     public GameObject[] obj;
     public AudioClip song;
     bool check = true;
     
     void Start ()
     {
         check = true;
         obj = GameObject.FindGameObjectsWithTag("Audio");
     }
     
     void Update () 
     {
         if (Input.GetKeyDown (KeyCode.P) && check == true)
         {
             foreach(object o in obj)
             {
                 //For each Obj from the array will be called PlaySound 
                 //function
                 //I need some help here.
             }
                 check = false;
         }
 
     }
     
     public  void PlaySound (AudioClip sound)
     {
 
         audio.clip = sound;
         audio.Play ();
     }
 
 
     public void PauseSound (AudioClip sound)
     {
         audio.clip = sound;
         audio.Pause ();
     }
 }


The array will contain all those gameObjects spread into my scenes from where will be played my Only mp3 file.

The problem is that by playing more than one sound at the same time in my scene (same mp3 file) will give me an echo and I dont want it to be.

I need help of how to do this.

Comment
Add comment · Show 5
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 getyour411 · Apr 24, 2014 at 10:32 PM 0
Share

I don't follow, the problem implies you want to play a sound file simultaneously on multiple gameobjects, the code stub you have setup also does as well since it's preparing to iterate over an array, but your closing comment implies you don't want to play more than one sound at the same time. That's the part that threw me.

Have you looked at audio.PlayClipAtPoint if you are trying to play the sound at a particular gameObject's location?

avatar image uanmanarmy · Apr 24, 2014 at 10:36 PM 0
Share

Well, I have 10 objects and I want to play for everyObject the same mp3 file. But I get that echo effect.

That's why im iterating through an array.

I tried with PlayClipAtPoint but still I got the effect of echochness, and this effect is due to playing the same file multiple times on different locations, because it's overlapping each other.

I want to get rid of that echo effect.

avatar image getyour411 · Apr 24, 2014 at 10:57 PM 0
Share

I'm sure I misunderstand, because if you have 10 things playing the same sound file the slightest differeces between them will put them out of exact synch so you'll get your 'echo'

avatar image MikeNewall · Apr 24, 2014 at 11:14 PM 0
Share

What do you need to play all those sounds at once for? It might be because your sound is set to 3D? if your audio listener isn't the same distance from each game object then you'll get an echo because Unity simulates the speed of sound which you can set in the audio manager. Try setting the sound to 2D in the import settings.

avatar image uanmanarmy · Apr 25, 2014 at 06:42 AM 0
Share

Imagine you have a big stage with a 10 speakers on it, How would you do to play the same song on each of them?

2 Replies

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

Answer by jabez · Apr 25, 2014 at 10:35 AM

Attach the script you have now to each gameobject you want sound to come from, then use AudioPlayScript.PlaySound(); you may have to change the PlaySound function in your script from public void to public static void, in another script put AudioPlayScript.PlaySound();, the only thing is you'll have to create a script for each sound. OR use this, i modified your script for you

   using UnityEngine;
     using System.Collections;
     
     public class AudioPlayScript : MonoBehaviour {
         
         public GameObject[] SoundSource;
         public AudioClip song;
         bool check = true;
         
         void Start ()
         {
             for(int i = 0; i < SoundSource.Length; i++) {
                 
             
             SoundSource = GameObject.FindGameObjectsWithTag("Audio"); // You may have to select the SoundSources in the inspector
             }
         }
         
         void Update ()
         {
             if (Input.GetKeyDown (KeyCode.P))
             {
                 PlaySound(song);
             
             }
             
         }
         
         public void PlaySound (AudioClip sound)
         {
             for(int i = 0; i < SoundSource.Length; i++) {
                 
                 SoundSource[i].audio.clip = sound;
                 SoundSource[i].audio.Play();
             }
         }
         
         
         public void PauseSound (AudioClip sound)
         {
             for(int i = 0; i < SoundSource.Length; i++) {
                 SoundSource[i].audio.clip = sound;
                 SoundSource[i].audio.Pause ();
             }
         }
     }
Comment
Add comment · Show 5 · 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 MikeNewall · Apr 25, 2014 at 10:46 AM 0
Share

You need to set the Doppler effect level to 0 for each audio source too or you get a weird chorusing effect when you move around.

avatar image jabez · Apr 25, 2014 at 10:56 AM 0
Share

add SoundSource[i].audio.dopplerLevel = 0.0f; to start function

avatar image uanmanarmy · Apr 25, 2014 at 05:57 PM 0
Share

For those with the doppler. I already had the doppler set to zero.

Doppler makes your audio wrong when you move, but even if I am not moving I got that effect of echo. This echo is due to multiple sounds played at once.

avatar image uanmanarmy · Apr 25, 2014 at 06:09 PM 0
Share

@jabez your script is perfect (I made something like this before), but $$anonymous$$y problem is not in doppler, my problem is in echo, and this echo effect is done by playing multiple sounds at the same time.

I still got it. :(

avatar image jabez · Apr 26, 2014 at 05:53 AM 0
Share

Hmm, You could just make it so the audio plays from the $$anonymous$$ain camera ins$$anonymous$$d of multiple objects but it wont be 3D sound.

avatar image
0

Answer by jakeflaze3859 · Aug 17, 2014 at 03:17 PM

I'm not sure if this is what your looking for, but could you just reduce the max distance under 3D sound settings in the audio source component?

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 uanmanarmy · Aug 22, 2014 at 12:29 PM 0
Share

yes, that was what I did. :D

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

23 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

Related Questions

Find all Objects/Scripts that access a given audio!! 1 Answer

Intensity of sound. 0 Answers

Truncate audio runtime 0 Answers

Audio Sounds Blurring Together 0 Answers

play audio from frequency and amplitude file 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges