Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

audio source

Discussion in 'Audio & Video' started by 2dgamemania, Mar 20, 2015.

  1. 2dgamemania

    2dgamemania

    Joined:
    Apr 30, 2014
    Posts:
    153
    Hi,

    I have an audio source on my main character, walking steps sound which has been dragged into the audioclip and works fine.

    I also have these gems objects that I collect and the script for the gems is on my main character and i use the following code for the gem script

    1. var gemsound : AudioClip;

    2. function Start () {
    3. GetComponent.<AudioSource>().clip=gemsound;
    4. }


    5. if (Col.gameObject.tag=="gems")
    6. {
    7. Destroy (Col.gameObject);
    8. collectablesdata.GetComponent.<collectables >().gems = collectablesdata.GetComponent.<collectables >().gems +1;
    9. GetComponent.<AudioSource>().clip=gemsound;
    10. GetComponent.<AudioSource>().Play();
    11. }
    this script works but the sound on the gem sound, sounds distorted or like its conflicting with the main character footstep sound. what i noticed was if i turn down the volume on the audiosource(the one for my main character foot steps) it also affects the volume on the gems....I need to seperate them so i can control both sounds , whats the best way? i'm using unity 5.

    Thanks
     
  2. proandrius

    proandrius

    Unity Technologies

    Joined:
    Dec 4, 2012
    Posts:
    544
    You should use different AudioSource for effects
     
  3. 2dgamemania

    2dgamemania

    Joined:
    Apr 30, 2014
    Posts:
    153
    do you mean add another audiosource object to my main character (so 2 audiosources on my main character)? and then assign the gem sound to it? i tried that and didnt work, it didnt seem to link and i dont understand why one audiosource component seems to control both sounds.
     
  4. proandrius

    proandrius

    Unity Technologies

    Joined:
    Dec 4, 2012
    Posts:
    544
    Don't assign two AudioSources to the same object. Just create another game object and use it for audio.
     
  5. 2dgamemania

    2dgamemania

    Joined:
    Apr 30, 2014
    Posts:
    153
    i just done that and the audiosource on my gem doesnt do anything but the audiosource on my main character still controls both sounds. Maybe cause the gem script is on my main character?