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.

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.