I want to add a simple sound on button click

Hi all! Im new in fmod and for education purposes I load this scene 2D Pixel Room Bedroom | 2D Environments | Unity Asset Store . 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.

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();
}

}


So i added button object and hooked a script on it. but nothing

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.

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.