Why does BeginScrollView make my buttons disappear?

Hi there,

I have a button that when clicked it spawns a set of buttons through a loop. Since the number of buttons increases over gameplay (the player can purchase new zones), I need to put all those buttons inside a scrollview.

My code so far:

if (_editing)
{
   for (int i = 0; i < _zones.Count; i++)
   {
	    // add slider
	    scrollPosition = GUI.BeginScrollView(new Rect(_buildingsBox.x + 5, _buildingsBox.y + 40, 200, 60), scrollPosition, new Rect(0, 0, 0, _unlockedLevelsAmount*100));

	     // add buttons
	     // Why do these buttons keep disappearing when using the scrollview?
	     if (GUI.Button (new Rect(_buttonRect.x, (_buttonRect.y+30*i), 100, 30), _zones*.name))*
  •   {*
    
  •         _editing = false;*
    

_selectedLevel = zones*.name;
_
}*

* GUI.EndScrollView();*
* }*
}
The buttons created by the loop disappear every time I click on the button to open the scrollview. However, if I create them manually, they don’t disappear when the scrollview begins. I’m sure there’s something silly I’m missing. Any help is appreciated.
Best,
Pzeronow

You mistake in line 6, when you initialization ScrollView. You write:

 scrollPosition = GUI.BeginScrollView(new Rect(_buildingsBox.x + 5, _buildingsBox.y + 40, 200, 60), scrollPosition, new Rect(0, 0, 0, _unlockedLevelsAmount*100));

In second Rect you set width is 0. Of couse, you don’t see you button. Change you code, how:

 //Maybe width scroll is 200
 scrollPosition = GUI.BeginScrollView(new Rect(_buildingsBox.x + 5, _buildingsBox.y + 40, 200, 60), scrollPosition, new Rect(0, 0, 200, _unlockedLevelsAmount*100));
 //Don't forget that coordinates of the button will be bound to a scroll
 if (GUI.Button (new Rect(_buttonRect.x, (_buttonRect.y+30*i), 100, 30), _zones*.name)) {*

_editing = false;
_selectedLevel = zones*.name;
_
}*

GUI.EndScrollView();
Generally, as it is correct to use scroll watch [my pregoing response][1].
_*[1]: http://answers.unity3d.com/questions/709793/make-guibeginscrollview-scroll-when-text-not-fit-o.html*_