- Home /
[4.6] Add scroll wheel functionality to scroll rect
So I have a scroll rect with an image and a mask and I can drag it with the mouse fine but how can I scroll with the mouse wheel?
I can add a scrollbar and again can drag that with the mouse but theres no scroll wheel functionality by default.
I tried adding an event trigger and changing the scrollbar value but can only set it to one value...
Surely it should be pretty simple?
Answer by gheeler · Sep 25, 2014 at 03:26 PM
I couldnt get this working properly but didn't try very hard as I was expecting it to be fixed by unity which it is now in beta release 19
Answer by orb · Sep 16, 2014 at 06:49 PM
There is an event for the scroll wheel, actually: IScrollHandler, with its OnScroll() event. It shows up in EventTrigger as "Scroll". Note that this is another case of the event data being a bit funky again, so it needs to be recast. Putting this method in a class called from EventTrigger works:
public void Scrolling(BaseEventData data)
{
PointerEventData ped = (PointerEventData)data;
Debug.Log(ped.scrollDelta.x+", "+ped.scrollDelta.y);
}
The y vector is the regular (vertical) scroll wheel. Positive is up. If you have a mouse with a secondary (horizontal) wheel it should show up as the x vector, but some of those mice can have the two swapped.
Your answer
Follow this Question
Related Questions
4.6 GUI Button inside a scrolling Text Box 0 Answers
Can you have a scrollview inside a textfield? 0 Answers
GUI wont show in for loop 1 Answer
ScrollWindow AutoUpdating value help :( 1 Answer
Unity v4.6 Joystick? 2 Answers