Author Topic: Slider Events Issue  (Read 5025 times)

cfj

  • Guest
Slider Events Issue
« on: May 14, 2012, 10:42:16 PM »
I cannot seem to get slider events to work.  I got button events to work with no problem but I am having issues with the sliders.  I even created a new project with just NGUI, added a UI, added a slider widget, created the following test script and attached it to the Slider:

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class test : MonoBehaviour
  5. {
  6.   void OnPress(bool isPressed)
  7.   {
  8.     Debug.Log("Slider Pressed");
  9.   }
  10. }
  11.  

When I press play, I can press and move the slider but nothing appears in the debug log.  I also looked at http://www.tasharen.com/temp/sigh/ in my research and I am attaching it to the actual Slider object with the UISlider component.  I am using version 2.0.5.  What am I missing?

loopyllama

  • Guest
Re: Slider Events Issue
« Reply #1 on: May 14, 2012, 11:48:58 PM »
I was involved in that other thread; the lesson was to disable the thumb collider because it grabs the OnPress event OR attach the script to both the slider and the thumb.

joreldraw

  • Guest
Re: Slider Events Issue
« Reply #2 on: May 15, 2012, 07:55:45 AM »
On your "Slider widget" you have the event Name... by default is "OnSliderChange"

Use this event to handle.

cfj

  • Guest
Re: Slider Events Issue
« Reply #3 on: May 15, 2012, 08:57:55 AM »
@loopyllama Thanks that worked.  Although, it is odd.  In the video he posted about your issue, he did not have to disable the thumb collider or attach the script to both the slider and the thumb.  Oh well, it works now.

@joreldraw I need to use the OnPress events because the eventReceiver fires if I update the sliderValue programmatically.  I need to distinguish between a programmed slider update (because of some other event) and the user actually clicking on the slider to move it.

loopyllama

  • Guest
Re: Slider Events Issue
« Reply #4 on: May 15, 2012, 09:54:41 AM »
I mention this in the thread with the video: he was sneaky in the video and didn't quite do the behaviour that shows the problem I was having. I was listening for slider changes in an OnSliderChange, which is why it appears to work. The script with OnPress = false was not being called properly and that script snaps the slider back to the middle. In the video he never does the behaviour to show the "bug" (which wasmy misunderstanding of the system). If he would have dragged by the thumb slider then released the slider would not have snapped back to the center because the script was not attached to the thumb and the thumb collider would have ate up the message.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Slider Events Issue
« Reply #5 on: May 15, 2012, 01:49:17 PM »
Sneaky. Ha. :D