- Home /
 
               Question by 
               kag359six · Nov 25, 2012 at 07:40 PM · 
                guiscrollviewscrollbar  
              
 
              ScrollView not....scrolling.
I'm not totally sure how the scrollView works exactly. When I tried implementing it, the buttons appear and all that good stuff, but the scrollbar doesnt move, and basically it doesn't scroll.
         scrollPosition = GUI.BeginScrollView(new Rect(0,50,width/2,height), scrollPosition,
             new Rect(0,0,width/2,height*2));
         
         float px = 0;
         float py = 0;
         float tw = 50;
         float th = 50;
         
         for(int i = 0; i < 10; i++) {
             
             GUI.Button(new Rect(px,py,tw,th), "button: " + i);    
             
             py += 75;
             
         }
 
         
         GUI.EndScrollView();
         
     }
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by DeveshPandey · Nov 26, 2012 at 12:08 PM
Try this:
 Vector2 scrollPosition = Vector2.zero;
 float height = Screen.height;
 float width= Screen.width;
 
 void OnGUI(){
 
 scrollPosition = GUI.BeginScrollView(new Rect(0,50,width/2,height), scrollPosition,
          new Rect(0,0,width/2,height*2));
 
        float px = 0;
        float py = 0;
        float tw = 50;
        float th = 50;
 
        for(int i = 0; i < 10; i++) {
 
          GUI.Button(new Rect(px,py,tw,th), "button: " + i);   
 
          py += 75;
 
        }
 
 
        GUI.EndScrollView();
 
     }
thanks forgot to set scrollView equal to scrollPosition
Answer by ExTheSea · Nov 25, 2012 at 09:01 PM
Where do you declare scrollPosition. If you declare it inside OnGUI() it won't work because it's reseting the scrollposition each Game Tick. You have to declare scrollposition outside of a function like this:
 var scrollPosition : Vector2;
Hope this works for you.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                