I am trying to make a select similar to HTML, tried this code, but scroll bar doesn’t move
GUILayoutOption[] opScroll = new GUILayoutOption[2];
opScroll[0] = GUILayout.Height(75);
opScroll[1] = GUILayout.Width(240);
GUILayout.BeginScrollView (new Vector2(0,0), false, true, opScroll);
string[] arrs = new string[7]{"opcion1","opcion2","opcion3","opcion4","opcion5","opcion6","opcion7"};
GUILayoutOption[] opSelect = new GUILayoutOption[2];
opSelect[0] = GUILayout.Width(210);
opSelect[1] = GUILayout.Height(100);
GUILayout.SelectionGrid(0,arrs,1,opSelect);
GUILayout.EndScrollView ();
I think I may have discovered your issue. You are storing the Scroll Bar position as 0,0 each time, but there doesn’t seem to be any code that changes it. Essentially, this would keep your scroll bar static no matter what you do.
Traditionally, GUILayout.BeginScrollView is called after declaring the Vector2 scrollPosition, like this:
public Vector2 scrollPos;
void OnGUI()
{
scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Width(50), GUILayout.Height(300));
GUILayout.Label("blah blah");
GUILayout.EndScrollView();
}
So, I’m pretty sure your code needs to read:
//Placed where you declare your other variables
public Vector2 scrollPos; //Declaring the vector 2 up here so it remembers where it is each time you call the scroll view
///////////////////////////////////////////////
//Placed wherever you placed this originally
GUILayoutOption[] opScroll = new GUILayoutOption[2];
opScroll[0] = GUILayout.Height(75);
opScroll[1] = GUILayout.Width(240);
scrollPos = GUILayout.BeginScrollView (scrollPos, false, true, opScroll); //This stores the position of the scroll bar to wherever you have moved it
string[] arrs = new string[7]{"opcion1","opcion2","opcion3","opcion4","opcion5","opcion6","opcion7"};
GUILayoutOption[] opSelect = new GUILayoutOption[2];
opSelect[0] = GUILayout.Width(210);
opSelect[1] = GUILayout.Height(100);
GUILayout.SelectionGrid(0,arrs,1,opSelect);
GUILayout.EndScrollView ();
////////////////////////////////////////////////////////////////
Hope this helps you out!
-Chuck
Many thanks, it worked fine