Author Topic: is it possible to use mouse scroll to move slider  (Read 3350 times)

pretender

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 155
    • View Profile
is it possible to use mouse scroll to move slider
« on: November 12, 2012, 05:37:55 PM »
like we use mouse scroll over dragable panels?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: is it possible to use mouse scroll to move slider
« Reply #1 on: November 12, 2012, 07:17:20 PM »
Just forward the OnScroll event to the object that has UIDragPanelContents on it.
  1. public class UIForwardScroll : MonoBehaviour
  2. {
  3.         public GameObject target;
  4.  
  5.         void OnScroll (float delta)
  6.         {
  7.                 target.SendMessage("OnScroll", delta, SendMessageOptions.DontRequireReceiver);
  8.         }
  9. }

pretender

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 155
    • View Profile
Re: is it possible to use mouse scroll to move slider
« Reply #2 on: November 13, 2012, 03:29:55 AM »
Actually i mean to move the slider with mouse scroll (not only with drag), is that possible?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: is it possible to use mouse scroll to move slider
« Reply #3 on: November 13, 2012, 03:54:48 PM »
Sure. Inside OnScroll, do something with the delta, such as uiSlider.sliderValue = uiSlider.sliderValue + delta * 0.1f;

pretender

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 155
    • View Profile
Re: is it possible to use mouse scroll to move slider
« Reply #4 on: November 14, 2012, 03:32:57 AM »
I dont seem to get it  :D

Here is what i did.

-attached UIForwardScroll to drag panel where slider is
-made target of UIForwardScroll to be a slider
-added this code to slider:
  1.         void OnScroll(float delta)
  2.         {
  3.                 Debug.Log(delta.ToString());           
  4.         }

when i use mouse scroll over slider nothing happens.
(for some reason only i can only make slider move by pressing on the thumb and dragging, other parts of the slider does not pick up presses although colliders are set properly)

what i am doing wrong, what is the right procedure to get this to work?

thank you very much!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: is it possible to use mouse scroll to move slider
« Reply #5 on: November 14, 2012, 11:51:00 AM »
That script needs to be attached to the object that has a collider. Panels don't have a collider. Try attaching it to the scroll bar instead. You basically have them backwards.