- Home /
Button audio get cut when pressing it
Hey guys, I have a script of main menu with "Join" button, I added an audio so when I click it does sound effect, but just by clicking on it the audio plays but dont finish, it just redirect me to where the button leads to (its like the audio get cut) is there any solution like adding a delay of 0.5sec so the audio can be fully heard? Thanks!
Post your code. The call to play a clip only needs to be sent once.
public class btnFX : $$anonymous$$onoBehaviour
{
public AudioSource myFx;
public AudioClip clickFx;
public void ClickSound()
{
myFx.PlayOneShot(clickFx);
}
}
Answer by Robertelis · Mar 22, 2019 at 01:45 PM
Try using OnClick()
function instead of the OnPointerDown()
function.
Answer by Azzid · Mar 22, 2019 at 02:21 PM
Thanks for your help, but I'm working on the same scene (the scene doesnt change after I click on the button but it loads a Panel) the issue here after few tries I ve noticed that the sound get cut because my Event Trigger is set on Pointer Down, so when I hold my pointer down I can hear the full audio, but if i click fast the audio is cut.. changing the pointer also doesnt make it work. Any suggestion I can do?
Nice! it works with OnClick() function, just dragged my AudioSource there + the audio I wanna play + I chose AudioSource.PlayOneShot. 100% works Thanks for your help!!
Good to know, I am going to edit my answer so other people can see it.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Glitched Music 0 Answers
Need help to add a script to an AudioManager 1 Answer
How to mute background music in just one scene 1 Answer
Scripts freezes game for a few seconds after build. 1 Answer