HELP ll Stuck with coding / button script

Hey guys i need help im about to cry

I want to create some sort of oneshot trigger audio for when a player touches the botton. This is the way it works untill now: in the gameObject/buttom, i add a component botton and a fmod event component emitter and drag the same gameObject with the fmod component and choose play in the on click section, this method works for almost every other botton in the scene but there are some buttons who dont.

so idk how but i created a script and i was capable of choose a event in the inspector and when i attached it in the gameObject it starts to play everytime cause i put the function on the Update() cell… the question here is how i can being able of make a script to when players actually press the gameObject/button and not reproduce the sound when the gameObject is enabled on the scene??? ill leave my script to u guys check it out.

i hope u guys understand English is not my first languge so i have a litte bit of problems when i do grammar

1 Like

this is the code:

as i say, the sound is shooting every frame cause is in the Update() cell, what i want is to sound when the player press the gameObject/button with the script in it.

PLEASE HELP IM DYING WITH THIS PROJECT

1 Like

Hi,

A solution may be using a custom function rather than update:

public FMODUnity.EventReference LightTouchEvent;
public FMODUnity.EventReference HardTouchEvent;

public void ButtonTriggerOneShot()
{
	FMODUnity.RuntimeManager.PlayOneShotAttached(LightTouchEvent, gameObject);
	FMODUnity.RuntimeManager.PlayOneShotAttached(HardTouchEvent, gameObject);
}

Then call the function from the button:

Hope this helps!

1 Like

Thank you!!! It worked perfectly!

1 Like