# I want to add a simple sound on button click

**URL:** <https://qa.fmod.com/t/i-want-to-add-a-simple-sound-on-button-click/21256>\
**Category:** FMOD Studio\
**Created:** [February 18, 2024, 11:45am UTC](https://qa.fmod.com/t/i-want-to-add-a-simple-sound-on-button-click/21256 "2024-02-18T11:45:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nikita3214](https://avatars.discourse-cdn.com/v4/letter/n/7993a0/32.png) [@Nikita3214](https://qa.fmod.com/u/Nikita3214)\
**Post date:** [February 18, 2024, 11:45am UTC](https://qa.fmod.com/t/i-want-to-add-a-simple-sound-on-button-click/21256/1 "2024-02-18T11:45:22Z")

</div>

Hi all! Im new in fmod and for education purposes I load this scene [2D Pixel Room Bedroom | 2D Environments | Unity Asset Store](https://assetstore.unity.com/packages/2d/environments/2d-pixel-room-bedroom-207779) . So I what to add a sound when shelf door open,for that i used some script,but nothing happen. Somebody could help pls? Script and scrins below.

---

<div class="post-metadata">

**Author:** ![Nikita3214](https://avatars.discourse-cdn.com/v4/letter/n/7993a0/32.png) [@Nikita3214](https://qa.fmod.com/u/Nikita3214)\
**Post date:** [February 18, 2024, 11:45am UTC](https://qa.fmod.com/t/i-want-to-add-a-simple-sound-on-button-click/21256/2 "2024-02-18T11:45:57Z")

</div>

using UnityEngine;

public class TriggerAudio : MonoBehaviour  
{  
public FMODUnity.EventReference shelf\_open;  
public string Event;  
public bool PlayOnAwake;  
public bool PlayOnDestroy;

```
public void PlayOneShot()
{
    FMODUnity.RuntimeManager.PlayOneShotAttached(Event, gameObject);
}

private void Start()
{
    if (PlayOnAwake)
        PlayOneShot();
}

private void OnDestroy()
{
    if (PlayOnDestroy)
        PlayOneShot();
}

```

}

---

<div class="post-metadata">

**Author:** ![Nikita3214](https://avatars.discourse-cdn.com/v4/letter/n/7993a0/32.png) [@Nikita3214](https://qa.fmod.com/u/Nikita3214)\
**Post date:** [February 18, 2024, 11:47am UTC](https://qa.fmod.com/t/i-want-to-add-a-simple-sound-on-button-click/21256/3 "2024-02-18T11:47:45Z")

</div>

![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/0/0b9a0fd2834a6a7eb0f0ffd42c5cf1a7fe0fba65.png)  
So i added button object and hooked a script on it. but nothing

---

<div class="post-metadata">

**Author:** ![Nikita3214](https://avatars.discourse-cdn.com/v4/letter/n/7993a0/32.png) [@Nikita3214](https://qa.fmod.com/u/Nikita3214)\
**Post date:** [February 18, 2024, 11:48am UTC](https://qa.fmod.com/t/i-want-to-add-a-simple-sound-on-button-click/21256/4 "2024-02-18T11:48:48Z")

</div>

![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/b/bbbb0bbaec29f65cf431cd53e28ac21808bc1fe2.png)

---

<div class="post-metadata">

**Author:** ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)\
**Post date:** [February 19, 2024, 6:05am UTC](https://qa.fmod.com/t/i-want-to-add-a-simple-sound-on-button-click/21256/5 "2024-02-19T06:05:21Z")

</div>

Hi,

In the second editor screenshot, it appears that “Play On Awake” and “Play On Destroy” in the `TriggerAudio` component are unchecked and therefore false, which would cause `PlayOneShot()` to not be executed in `TriggerAudio`. Try setting those variables to true in the inspector, and seeing whether that fixes the issue.

---

<div class="post-metadata">

**Author:** ![Nikita3214](https://avatars.discourse-cdn.com/v4/letter/n/7993a0/32.png) [@Nikita3214](https://qa.fmod.com/u/Nikita3214)\
**Post date:** [February 19, 2024, 7:15am UTC](https://qa.fmod.com/t/i-want-to-add-a-simple-sound-on-button-click/21256/6 "2024-02-19T07:15:48Z")

</div>

it didnt help. sound now is playing at the beggining of the scene,but not when i click a button.

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/2/208214bb11022f9dc3235e60115d2f92e173f313.png)

---

<div class="post-metadata">

**Author:** ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)\
**Post date:** [February 19, 2024, 11:20pm UTC](https://qa.fmod.com/t/i-want-to-add-a-simple-sound-on-button-click/21256/7 "2024-02-19T23:20:02Z")

</div>

> [@Nikita3214](#):
>
> it didnt help. sound now is playing at the beggining of the scene,but not when i click a button.

Yes, this is because your call to `PlayOneShot()` is in `Start()`. If you want to play the one shot on click, you’ll need to use the appropriate method or callback instead of `Start()`, which I believe in this situation is [`Button.clicked`](https://docs.unity3d.com/ScriptReference/UIElements.Button-clicked.html).
