• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by james-stanton · Oct 23, 2015 at 12:24 PM · uiaudioslidervolume

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.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Socapex · Oct 29, 2015 at 12:12 PM 0
Share

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? :)

avatar image james-stanton Socapex · Oct 29, 2015 at 04:41 PM 0
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image keanpatrickalfon · Dec 16, 2020 at 12:16 PM 0
Share

Hi can ask how can i able to disable the sliding sound effect in handle slider not on everytime i click

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Linear volume control of AudioMixer groups 0 Answers

changing game volume 3 Answers

PlayerPrefs not saving slider value & audio 2 Answers

The volume does not reduce when master volume is lowered using volume slider 3 Answers

Getting the Value of a slider with 4.6 UI 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges