Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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
1
Question by bkachmar · Dec 30, 2016 at 04:27 AM · uiinputeventsliderinputfield

UI slider "End slide" event

Hello,

The Input Field script form Unity UI has "On Value Changed" and "On End Edit" event listeners. Is there any event for Slider similar to the second one from Input Field?

I mean I would like to have an event that fires after user finishes dragging the handle on Slider, so that I will adjust everything to the final value the user wants.

I was thinking of putting some kind of coroutine that will track 0.3 seconds after last "OnValueChanged" event and then readjust everything, but that sounds very messy.

In case someone had this trouble or knows how to fix it - would be glad to see an answer =)

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by LK84 · Dec 30, 2016 at 08:30 AM

Drag this script on your Slider GameObject:

   using UnityEngine;
   using System.Collections;
   using UnityEngine.EventSystems;
     
   public class SliderDrag : MonoBehaviour,IPointerUpHandler {
     
         public void OnPointerUp(PointerEventData eventData)
         {
             Debug.Log("Sliding finished");  
         }
 }

Comment
Add comment · Show 2 · 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 pookus · Aug 10, 2017 at 09:00 AM 0
Share

Does the job, Thanks.

avatar image adikecapan · Feb 17, 2021 at 05:39 AM 0
Share

Thanks, it works

avatar image
2

Answer by gheeler · Feb 15, 2018 at 11:43 AM

I came across this and thought I'd add a bit so you have an event that you can access elsewhere like OnValueChanged

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.EventSystems;
 using UnityEngine.UI;
 
 public delegate void EndSliderDragEventHandler (float val);
 
 [RequireComponent(typeof (Slider))]
 public class SliderDrag : MonoBehaviour, IPointerUpHandler 
 {
     public event EndSliderDragEventHandler EndDrag;
 
     private float SliderValue {
         get {
             return gameObject.GetComponent<Slider>().value;
         }
     }
 
     public void OnPointerUp (PointerEventData data)
     {
         if (EndDrag != null) 
         {
             EndDrag(SliderValue);
         }
     }
 }


Comment
Add comment · 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
0

Answer by geonak · Jun 10, 2020 at 09:48 AM

I came across this as I was looking for something similar, I thought I'd add my finding as it might help someone.

The easiest way I found is to add an Event trigger component to the slider, in addition to the slider component. You then add a new 'pointer up' event type to that Event trigger, and you set it the usual way to call whatever function you want.

This way the standard slider component will handle the On Value Changed, and your new Event trigger will handle the on release.

Comment
Add comment · 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

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.

Follow this Question

Answers Answers and Comments

98 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Hover Over Input Field Before Inputting? 2 Answers

Can I disable the use of Input.GetKey(KeyCode("any key")) while an InputField is in use? 2 Answers

UI Toolkit - prevent click through visual element 1 Answer

New gui: How to disable keyboard input when user is typing? 2 Answers

UI InputField text sometimes invisible? 1 Answer


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