Hi,
Basically what i want to do is a menu - much like the android main menu and the iphone homescreen.
I have been struggling with this one for about a 5 hours now, so help will be much appreciated.
I have a panel “A” with scrollrect script on it.
Inside it I have two more panels “B” and “C” (let’s call them pages);
Panels “B” and “C” have a GridLayoutGroup scripts that holds a number of elements - lets call them Icons.
Now, each Icon (element in panels B or C) have a script attached called “Dragable”. It basically makes them move with the mouse on drag (while draging an icon, it sets it position to the position of the mouse).
Everything so far works great. But now I’m trying to add the ability to change pages (panels B and C) with swiping on the screen). Obviously if i just swipe the screen I start moving the icon my finger has landed on (except if I touch where there is no icon, then pages swipe correctly). To escape this I added a check - if i hold my finger on the icon for 1 second - then I set a flag “isDragged” and move it with the pointer. If I don’t wait that 1 second, the flag isDragged is false, and then I do this:
public void OnDrag (PointerEventData eventData) {
if (!isDraged) {
eventData.pointerDrag = transform.parent.parent.gameObject;
return;
}
this.transform.position = eventData.position;
}
Basically if isDragged is false, I change the receiver of the dragging - to the scrollrect.
This also works somewhat fine - the only problem, and this is where I need your help - is that no matter where on screen I click, the draging point (like the point where i hold the scrollrect) is where i last clicked on the scrollrect.
What I mean is, if I click and drag whitout doing anything else first, the scrolrect content moves so my mouse is pointing in the middle of it. But if I click on any other place on the content before that (where no icon is in the way) then when I do a new drag, the whole content jumps so my mouse is pointing in the location i clicked earlier.
I feel like there is some variable “PlaceWhereMouseClicked” that is holding the coordinates of where the dragging is coming from. What I want to do is change it - so the draging comes from where my drag started, not where i cleicked earlier.