- Home /
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();
}
Answer by Ochreous · Sep 20, 2012 at 05:14 AM
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.
Answer by kmeboe · Sep 20, 2012 at 12:48 AM
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: http://docs.unity3d.com/Documentation/ScriptReference/GUILayout.BeginScrollView.html
I did everything in the tutorial but the Horizontal Scrollbar still didn't show up.
Answer by kmeboe · Sep 20, 2012 at 03:56 AM
Try the following steps:
Create a new project
Create a new C# script called "test".
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 += "\nHere is another line"; } }
Attach the test script to the main camera.
Give this a shot, and let me know if the scroll bar shows up.
Not sure why the formatting is messed up. $$anonymous$$ake sure you grab everything, starting at "using UnityEngine", and ending at the last bracket, which is outside the code block;. Some of the newlines will be missing, but they're not needed.
Your answer
Follow this Question
Related Questions
C# How to Drag and Scale with Mouse Window 0 Answers
Changing GUI.Box opacity 3 Answers
A node in a childnode? 1 Answer