- Home /
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?
I have also tried SelectionGrid with the same inability to communicate out of the ScrollView
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.
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.
It does not show in the code above but there is an GUI.EndScrollView(); After that comment up above in my code.
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 .....
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
}
}
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
![](https://koobas.hobune.stream/wayback/20220613132636im_/https://answers.unity.com/themes/thub/images/avi.jpg)