Support => NGUI 3 Support => Topic started by: cfj on May 14, 2012, 10:42:16 PM
Title: Slider Events Issue
Post by: cfj 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:
usingUnityEngine;
usingSystem.Collections;
publicclass test : MonoBehaviour
{
void OnPress(bool isPressed)
{
Debug.Log("Slider Pressed");
}
}
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?
Title: Re: Slider Events Issue
Post by: loopyllama 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.
Title: Re: Slider Events Issue
Post by: joreldraw 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.
Title: Re: Slider Events Issue
Post by: cfj 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.
Title: Re: Slider Events Issue
Post by: loopyllama 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.
Title: Re: Slider Events Issue
Post by: ArenMook on May 15, 2012, 01:49:17 PM