public ListitemList = new List () { "item 1", "item 2", "item 3", "item 4", "item 5" }; public Vector2 scrollPosition = Vector2.zero; void OnGUI() { GUILayout.BeginArea(new Rect(10, 10, 200, 300)); scrollPosition = GUILayout.BeginScrollView(scrollPosition); foreach(string item in itemList) { GUILayout.Label(item); } GUILayout.EndScrollView(); GUILayout.EndArea(); }
public int itemCount = 15; public float buttonHeight = 50f; public Vector2 scrollPosition = Vector2.zero; void OnGUI() { GUILayout.BeginArea(new Rect(10, 10, 200, 300)); scrollPosition = GUILayout.BeginScrollView(scrollPosition); for(int i = 0; i < itemCount; i++) { if(GUILayout.Button("Button " + i, GUILayout.Height(buttonHeight))) { Debug.Log("Button " + i + " was clicked!"); } } GUILayout.EndScrollView(); GUILayout.EndArea(); }Both examples use the GUILayout.BeginScrollView method to create a scrollable area with a dynamic or fixed content. The scrollPosition vector is used to control the position of the scroll view. The first example uses GUILayout.Label to create dynamic content, while the second example uses a series of GUILayout.Buttons to create fixed content. The UnityEditor package is required for both examples.