Author Topic: Scroll View with buttons  (Read 4549 times)

recon03

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
Scroll View with buttons
« on: August 17, 2014, 02:54:53 AM »
I have a left  button that will make it scroll left as you click it.  I will have a right button  that when you click it scrolls right.   I do not want this on drag.  I did this and got some what working but its not working 100 %

What is the best way to handle this?

Thanks.

recon03

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: Scroll View with buttons
« Reply #1 on: August 17, 2014, 03:49:02 AM »
  1. UIScrollBar hScrollbar;
  2.         UIScrollBar vScrollbar;
  3.  
  4.  
  5.  
  6.         public float keyboardSensitivity = 1;
  7.  
  8.         void Awake()
  9. {
  10. //              //Assign both scrollbars on Awake
  11.                 hScrollbar =
  12.                         GetComponent <UIScrollBar> ();
  13.  
  14.                 vScrollbar = GetComponent<UIScrollBar> ();
  15.         }
  16.  
  17.         void Update()
  18.         {
  19.                 //Get keyboard input axes values
  20.                 Vector2 keyDelta = Vector2.zero;
  21.                 keyDelta.Set(Input.GetAxis("Horizontal"),
  22.                              Input.GetAxis("Vertical"));
  23.                 //If no keyboard arrow is pressed, leave
  24.                 if(keyDelta == Vector2.zero) return;
  25.                 //Make it framerate independent and multiply by sensitivity
  26.                 keyDelta *= Time.deltaTime * keyboardSensitivity;
  27.                 //Scroll by adjusting scrollbars' values
  28.                 hScrollbar.value += keyDelta.x;
  29.                 vScrollbar.value -= keyDelta.y;
  30.         }
  31.  
  32. }
  33.  

recon03

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: Scroll View with buttons
« Reply #2 on: August 17, 2014, 03:50:03 AM »
The slider it self works perfectly in the inspector.  The view port only moves once in awhile.  So not sure what I'm missing here.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scroll View with buttons
« Reply #3 on: August 17, 2014, 10:03:40 AM »
Scroll bar value is 0 to 1 range. Check what values keyDelta is turning out to be.