Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Play Audio when Button is pressed

Discussion in 'Audio & Video' started by abdoubelbala, Jan 31, 2015.

  1. abdoubelbala

    abdoubelbala

    Joined:
    Aug 4, 2012
    Posts:
    51
    Hi guys i have a problem, this is a screenshot of my scene

    i have add an audio source to the scene and attache it to the button and every thing looks good , what i want is that when the player click on the button image , a sound will be played , the same thing for the next button but when i click in the next button i have 2 audio sources is playing , i don't know how i can fix that problem , if there is a suggestion please give it to me thank you.
     
  2. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,555
    You could just use a single Audio Source for all the "like" sounds (such as button sounds), then assign different Audio Clips to the Audio Source and play it when another sound needs to be played. If it's the same Audio Clip for each then you don't need to assign the clip and you can just call Audio.Play again.
     
    abdoubelbala likes this.
  3. abdoubelbala

    abdoubelbala

    Joined:
    Aug 4, 2012
    Posts:
    51
    thank you.
    but i want to stop the audio source number 1 when i play the second audio source.
     
  4. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,555
    There's only 1 Audio Source shared among all the buttons, not one for each. That's what I meant.
     
    abdoubelbala likes this.
  5. abdoubelbala

    abdoubelbala

    Joined:
    Aug 4, 2012
    Posts:
    51
    Yes i have test it it works .
     
    jerotas likes this.