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
0
Question by diggerjohn · Feb 05, 2014 at 09:39 PM · guibuttonongui

Buttons within Scroll View not able to communicate

I have some buttons within a ScrollView. And they don't seem to be able to communicate out of the view. What I have is

function OnGUI () {

 if (GUI.Button(new Rect (0, 0, 100, 20), "1")){
     GUI.Label(Rect(150, 0, 200, 20), "You picked IT");
     Debug.Log("this buttons name is working");
 }
 // Begin the ScrollView
 scrollViewVector = GUI.BeginScrollView (Rect (200, 100, 200, 100), scrollViewVector, Rect (0, 0, 400, 400), false, true);
 
 // Put something inside the ScrollView
 if (GUI.Button(new Rect (0, 0, 100, 20), "1")){
     GUI.Label(Rect(400, 100, 400, 20), "You picked #1", listStyle);
     Debug.Log("IN BUTTON 1");
     
 }
 
 if (GUI.Button (Rect (0,21,100,20), "2")){
     GUI.Label (Rect(200, 70, 200, 20), "You picked #2", listStyle);
     Debug.Log("IN BUTTON 2");
 }
     //GUI.Button (Rect (0,0,100,20), "1");
     //GUI.Button (Rect (0,21,100,20), "2");
     GUI.Button (Rect (0,41,100,20), "3");
     GUI.Button (Rect (0,61,100,20), "4");
     GUI.Button (Rect (0,81,100,20), "5");
     GUI.Button (Rect (0,101,100,20), "6");
     GUI.Button (Rect (0,121,100,20), "7");
     GUI.Button (Rect (0,141,100,20), "8");
     

// End the ScrollView GUI.EndScrollView(); }

So the first button created is outside the view and works just fine. But those created inside render and interact but will not communicate. Thoughts?

Comment
Add comment · Show 7
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 diggerjohn · Feb 05, 2014 at 10:13 PM 0
Share

I have also tried SelectionGrid with the same inability to communicate out of the ScrollView

avatar image ArkaneX · Feb 05, 2014 at 11:04 PM 0
Share

What do you mean by 'not able to communicate'?

avatar image Scribe · Feb 06, 2014 at 12:45 AM 0
Share

The buttons within the scroll view work fine for me, pressing the first 2 buttons in the scroll view prints "IN BUTTON 1" and "IN BUTTON 2" successfully.

avatar image diggerjohn · Feb 06, 2014 at 01:31 PM 0
Share

ArkaneX - By Communicate I mean being able to send a message from the button out beyond the scroll view.

Scribe - That is fantastic, just wish I was getting the same result. I get no output at all. Is it possible that there is a setting somewhere I am missing? This is really frustrating.

avatar image diggerjohn · Feb 06, 2014 at 01:54 PM 0
Share

It does not show in the code above but there is an GUI.EndScrollView(); After that comment up above in my code.

Show more comments

2 Replies

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

Answer by diggerjohn · Feb 06, 2014 at 02:33 PM

Seems that it was the GUI.TextArea (Rect (0, 0, 400, 400)); I commented this out and it is all working. Buttons within the scroll are working. So now I just need to figure how to get the interior of the scroll area to be distinguished from the background, as in background color and I am home. Nice .....

Comment
Add comment · 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
0

Answer by giudark · Feb 06, 2014 at 02:25 PM

2 problem: first if you do this :

 if (GUI.Button(new Rect (0, 0, 100, 20), "1")){
     GUI.Label(Rect(400, 100, 400, 20), "You picked #1", listStyle);
     Debug.Log("IN BUTTON 1");
 }

you can see the label only in the frame in which the button was pressed, so practically invisible .. (but log remains in the editor, however)

second if you place your label inside the scrollView the coordinates are relative to it, your scrollView is 200 unit wide and you are placing your label at 200 or 400 (so to the right) and also you are not showing the horizontal scroll bar.

try this:

 var visibleLabel : boolean = false;

 function OnGUI () {
     //other stuff ..

     scrollViewVector = GUI.BeginScrollView (Rect (200, 100, 200, 100), scrollViewVector, Rect (0, 0, 400, 400), false, true);
     if (GUI.Button(new Rect (0, 0, 100, 20), "1")){
         visibleLabel = true;
         Debug.Log("IN BUTTON 1");
     }
     //....
     GUI.EndScrollView(); 

     if(visibleLabel){
          GUI.Label(Rect(400, 100, 400, 20), "You picked #1", listStyle);
          //absolute coordinates
     }
 }
Comment
Add comment · Show 2 · 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 diggerjohn · Feb 06, 2014 at 02:44 PM 0
Share

Sweet, thanks so much giudark!

avatar image diggerjohn · Feb 06, 2014 at 03:27 PM 0
Share

Found that simply calling the GUI.TextArea after creating the buttons put that color in the background and allows the buttons to work correctly.

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

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problem with controlling a 2D array to display strings on GUI. 2 Answers

Slider & Button Interaction Problem 0 Answers

Making texture cover whole button 1 Answer

GUI.DrawTexture on GUI.Button press 1 Answer

How to give animation to the on gui button? 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