I've already read the documentation of the GUILayout.BeginScollView. It is just that I don't understand on how to apply the "alwayShowHorizontal" to false. Here's my code :-
scrollPosition = GUILayout.BeginScrollView(scrollPosition,GUILayout.Width (Screen.width*30/160), GUILayout.Height(Screen.width*38/160-Screen.height*1/25));
----------Edited to insert image-------- This is the result I get:-
Always show horizontal will default to false if you don't set it.
@Gizmoi, above I uploaded the result that I get. According to my code I didn't set the parameters, didn't I?
Do you want to just hide the scrollbar or to prevent the scrollview from scrolling horizontally?
If you want to hide it, just use a custom GUIStyle which doesn't contain an image for the background / thumb...
Answer by Baalhug
Feb 04, 2014 at 03:25 PM
If you dont want horizontal scrollbar to show, then your inside rect width must be lower than the rect containing it. This means:
When you call GUI.BeginScrollView you must declare 2 rects (http://docs.unity3d.com/Documentation/ScriptReference/GUI.BeginScrollView.html) The goal of scrollview is to let you draw GUI elements bigger than the area you have to show them, and this is only possible by using scrollbars, as you may understand. So you declare a rect defining the area you have, and another rect defining the real size of your gui content (window, or whatever). Now, if height of the real area is bigger than the display area (change word area by rect, in practise) then a vertical scrollbar will show. If not, you can force it to show by using alwaysShowVertical. The same happens for width.
Conclussion. The only way to avoid horizontal scrollbar shows in scrollview is by defining a rect for the real content equal or smaller than the rect for display. Otherwise, some content would be hidden with no chance to see it.
Answer by Gizmoi
Feb 05, 2013 at 03:08 PM
float width = Screen.width * 30 / 160;
float height = Screen.width * 38 / 160 - Screen.height * 1 / 25;
scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, true, GUILayout.Width(width), GUILayout.Height(height));
That will set alwaysShowHorizontal to false and alwaysShowVertical to be true.
Thanks! Although I now realized that set it to "true" the option only force the scroll bar to appear before content is out of the area. By default(false) it only appears after the content breach the border. So that means that force disabling it is not possible. At least now I know how to use the extended parameter. Thanks again!
Answer by Ramy-TL
Feb 28 at 07:51 AM
scrollPos = GUILayout.BeginScrollView(scrollPos, false, false, GUIStyle.none, GUI.skin.verticalScrollbar);
I hope this helps
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
14 People are following this question.
GUIlayout scrollbar, Not working well...
How to change thickness of ScrollBar of GUILayout ScrollView?
GUILayout.BeginScrollView how to create new row?
scrollbar GUI Skin problem
GUI how to use scrollbar