- Home /
Volume Slider - Play a sound after modifying slider value and releasing the mouse
Hi Guys,
I am trying to make my volume slider play a sound AFTER the slider is adjusted and the mouse is released (think Windows OS volume slider).
Here is my C#:
public void PlayVolumeCheck(){
if (Input.GetMouseButtonUp(0)) {
Vector3 temp = new Vector3 (9f, 5f);
Debug.Log ("ping!");
AudioSource.PlayClipAtPoint (paddleHit, temp , 2f);
}
}
I have tested this by adding it to the Update Function and it works fine ( I click anywhere on the game screen and it pings after releasing the mouse button).
If I remove the If statement and just have it playing the sound, it works but it plays the sound every time the slider value changes, so it sounds very bad.
Thanks in advance.
So what is the exact issue? You are not hearing the sound on mouseUp after the slider is moved I guess? If so, it is probably because it is only called once, and doesn't "catch" the mouseUp.
You could do a simple bool sliderDirty
, and then check that in Update(). So when you edit a slider, set sliderDirty = true;
and when you get the mouseUp, sliderDirty = false;
$$anonymous$$akes sense? :)
Hi Socapex,
Sorry I don't really understand what you are describing there.
Not to worry though, I have already fixed this and posted an answer but it's yet to be approved by a mod.
I used an Event Trigger with a Pointer Up check attached to the parent.
Answer by james-stanton · Oct 29, 2015 at 07:33 PM
Well I managed to fix it, though it's not pretty nor elegant...
I added an 'Event Trigger' to the Slider object itself (not any of its children).
I then set the Event Trigger to run:
Vector3 temp = new Vector3 (9f, 5f);
Debug.Log ("ping!");
AudioSource.PlayClipAtPoint (paddleHit, temp , 2f);
When it detects a mouse up event.
Hi can ask how can i able to disable the sliding sound effect in handle slider not on everytime i click
Your answer
Follow this Question
Related Questions
Getting the Value of a slider with 4.6 UI 2 Answers
Vertical Slider - Using different art? 1 Answer
AudioListener.volume doesn't change the volume 4 Answers
Linear volume control of AudioMixer groups 0 Answers
changing game volume 3 Answers