Creating multiple EditorGUILayout.Foldout -s


When I write this code :

var b : boolean;

 for (var i=0; i<=5; i++){
	b = EditorGUILayout.Foldout(b, "test");		
if (b){
 GUILayout.Button ("test");	

I get 6 foldouts and when I try to open one of them, all other open. Also, only one button shows up.

What I want to do is create N number of foldouts and each should open separately from other foldouts.

Problem is, I can’t manage to make it work.

I tried to make array of booleans and pull them through for loop, something like this :

for (var i =0; i<=5; i++){
 b _= EditorGUILayout.Foldout (b*, "Something");*_

if (b*){*
// something
But that doesn’t work.
By additional googling I found out that people did use that code above before and it worked.
Where am I making mistake ?

Why should using an array of boolean values not work? How does your declaration of your array looks like? Do you get any errors? You most likely did something wrong with your array, but you didn’t include the declaration and creation of the array. So basically you post a question about a problem with a piece of code you don’t include in the question. That doesn’t make much sense.

To declare a boolean array in UnityScript you should have a line like this:

var b : boolean[] = new boolean[5];

in C# it would look like this:

bool[] b = new bool[5];

Also your if block should be inside the for loop. You can’t use the for-loop variable “i” outside of the loop.