HorizontalScrollbar not appearing in GUILayout.BeginScrollview C#

Hi everyone, I have been trying to get the Horizontal Scrollbar to appear in GUILayout.BeginScrollview.But for some reason I just can’t get it to appear. Do I need to setup different parameters to get it to appear?

    public Vector2 scrollPosition;
   
    void OnGUI() {
        scrollPosition = GUILayout.BeginScrollView(scrollPosition,
        GUILayout.Width(100), GUILayout.Height(100));

     
        
        GUILayout.EndScrollView();
        
        
    }

I believe you have to add enough content to the view before the bar will show up. If the content can fit inside the width/height you’ve defined, the scroll bars won’t show up.

Follow the example on this page, and see if it works: Unity - Scripting API: GUILayout.BeginScrollView

Try the following steps:

  1. Create a new project

  2. Create a new C# script called “test”.

  3. Paste the following code into test:

    using UnityEngine;
    using System.Collections;

    public class test : MonoBehaviour {
    public Vector2 scrollPosition;
    public string longString = “This is a long-ish string”;
    public string longerString = “This is an even longer string. It is very long. I’m still talking about the string.”;

    void OnGUI() {
        scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width(100), GUILayout.Height(100));
        GUILayout.Label(longString);
    	GUILayout.Label(longerString);
        if (GUILayout.Button("Clear"))
            longString = "";
        
        GUILayout.EndScrollView();
        if (GUILayout.Button("Add More Text"))
            longString += "
    

Here is another line";

    }
}
  1. Attach the test script to the main camera.

Give this a shot, and let me know if the scroll bar shows up.

I figured out how to make the horizontal scrollbar show up. You have to put in two booleans in the beginscrollview. One bool is for the horizontal scrollbar and the other is for the vertical scrollbar.