I want to place a button within a ScrollView and have it move as the ScrollView changes. Currently I have the buttons placed, but they do not move when the scrollview changes, though the rest of the contents do.
private Vector2 scrollPositionSchematics = new Vector2(0,0);
private GUIStyle style = new GUIStyle ();
private Objtect[] schematicsArray = Resources.LoadAll ("Prefabs/Rooms");
//Handles the HUD-GUI
void OnGUI(){
/*-----------------------------------------------------------------------------------------
*
* Create the frame and contents for the HUD(Schematic) area
*
*---------------------------------------------------------------------------------------*/
HUDWindow ("Schematic", //text to display in the header
19, //size of the font
(int) Mathf.Floor(Screen.width/3*2), //positionX
(int) Mathf.Floor(Screen.height/5*4), //positionY
(int) Mathf.Floor(Screen.width/3), //xSize
(int) Mathf.Floor(Screen.height/5) //ySize
);
//Display text for HUDWindow(Function)
GUILayout.BeginArea (new Rect ((int) Mathf.Floor(Screen.width/3*2)+7,(int) Mathf.Floor(Screen.height/5*4)+50,(int) Mathf.Floor(Screen.width/3),(int) Mathf.Floor(Screen.height/5*4)));
scrollPositionSchematics = GUILayout.BeginScrollView (scrollPositionSchematics,
false,
true,
GUILayout.Width(Mathf.Floor(Screen.width/3)-10),
GUILayout.Height(Mathf.Floor(Screen.height/5)-50));
style.fontSize = 14;
style.normal.textColor = Color.black;
style.wordWrap = true;
GUILayout.Label ("This is the Schematic tab.", style);
CreateSchematicButtons ();
GUILayout.EndScrollView ();
GUILayout.EndArea ();
}
void CreateSchematicButtons(){
//button size
int buttonWidth = 50;
int buttonHeight = 50;
//for every item contained in the schematicsArray, place a button
for (int i = 0; i<schematicsArray.Length; i++){
if(GUI.Button(new Rect(0, scrollPositionSchematics.y+buttonHeight*i, buttonWidth, buttonHeight), "Button "+i)){
Debug.Log("Pressed button #"+i);
}
GUILayout.Space(buttonHeight);
}
}