Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by Youngapprentice · Dec 22, 2011 at 11:02 PM · guiviewscrollbox

GUI Scroll View

Hi, all! I am trying to make a GUI scroll box in a chat box that scrolls ONLY VERTICALLY. I looked up GUI.ScrollView in the reference but I just can't seem to wrap my head around it.

This is the portion of code I grabbed from the page...

     // An absolute-positioned example: We make a scrollview that has a really large client
     // rect and put it in a small rect on the screen.
     scrollposition = GUI.BeginScrollView (Rect (10,300,100,100),
         scrollposition, Rect (0, 0, 220, 200));
     
     // Make four buttons - one in each corner. The coordinate system is defined
     // by the last parameter to BeginScrollView.
     GUI.Button (Rect (0,0,100,20), "Top-left");
     GUI.Button (Rect (0,180,100,20), "Bottom-left");
     // End the scroll view that we began above.
     GUI.EndScrollView ();
 }

This is all fine and dandy, but I have a few questions: A. Why is it that the first two lines (after the comments) are not connected? what do they do? Does it supply a domain and then a box or what? B. when I insert my own values, to fit the chat box, nothing shows up. Why?

alt text

Thanks- YA

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
6
Best Answer

Answer by Bunny83 · Dec 22, 2011 at 11:40 PM

Ok, it seems you missed some basic syntax rules ;)

The compiler doesn't care for new lines or indent-spaces in the first place (except for single-line comments which are terminated at a new line character). Every script could be written in a single line but that's a total mess to read for humans. That's why we struct our scripts in a way that you can easy read and understand what the script does.

Something like that:

scrollposition = GUI.BeginScrollView (Rect (10,300,100,100), scrollposition, Rect (0, 0, 220, 200));

Can also be written like that:

scrollposition = GUI.BeginScrollView (
                      Rect (10,300,100,100),     // screen position
                      scrollposition,            // current scroll position
                      Rect (0, 0, 220, 200)      // content area
                 );

There's absolutely no difference in those two forms. It's just to avoid long single-line commands so you don't have to scroll sideway to view it.

The scrollview itself is quite simple. the first parameter defines the rectangle on the screen where your scrollview should be displayed and at what size. In your example at position (10, 300) and the size is (100, 100).

The "scrollposition" is a variable that stores the current scrollposition.

The content area (viewrect) is your virtual space inside the scrollview. in this area you define your GUI elements (buttons, labels, ...). From this area you only see a fraction since the viewable size on screen is defined with (100, 100).

If you don't want to scroll sideways you should make your content rectangle's width smaller so it can be displayed completely inside the visible area. The height should be big enough (more than the viewable area) so it gets actually scrolled.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Youngapprentice · Dec 23, 2011 at 12:26 AM 0
Share

So you are saying that the scrollview's height should be larger than the viewrect's height, or the other way around.

Also, nothing shows up if I set the same coordinates/sizes for each one... not eve the buttons. What's up with that?

Thanks!- YA

avatar image Youngapprentice · Dec 23, 2011 at 01:19 AM 0
Share

Thanks for the help. It works like a charm now!

avatar image Bunny83 · Dec 23, 2011 at 01:53 AM 0
Share

Read it carefully. The first provided Rect defines the GUI element itself (like a button, label) in screen coordinates. The second Rect is the movable area inside the scrollview which defines how much space is inside the scrollview. If the second Rect is 10 times larger than the visible Rect(the first one) you have 10 pages which you can scroll up and down.

The second rect should always start at (0,0). Only the size is important.

avatar image Anni2D · Aug 09, 2014 at 09:15 AM 0
Share

Thanks for explanation. Quite helpful.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Sensing if a string is multi - lined 2 Answers

Alternative to GUI Scrollview ? 1 Answer

Problem with modifying scrollPosition on android 1 Answer

Can I use a movie texture with alpha as a GUI object? 1 Answer

how make a for loop that makes GUI boxes ? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges