- Home /
Question by
AKhilles47 · Mar 27, 2014 at 08:45 PM ·
buttonfor loop
I want to make buttons by clicking one button
If I comment out my first button creation, the loop of buttons are created fine, but when I keep the if statement in, it only creates the first button. I understand that I need to click the button to create the others, but it does not make the other buttons but it does enter the for loop. Can anyone help me understand why this is happening? if you need more info, I am more than willing to help.
void makeEvolutionWindow(int windowID)
{
GUI.DrawTexture (new Rect (0, 0, Screen.width * .6f, Screen.height * .6f), evolHeirBackground);
GUI.skin.button.wordWrap = true;
string directoryPath = Directory.GetCurrentDirectory () + "/assets/prefabs/player prefabs/resources/bodyparts";
//print (directoryPath);
string[] directories = Directory.GetDirectories(directoryPath);
//print (directories [0]);
foreach (string curPath in directories) {
int i = curPath.Length - 1;
string folderName = "";
char c = ' ';
do {
folderName = c + folderName;
c = curPath[i];
i--;
} while (c != '/');
if (GUI.Button ( new Rect(0,40,100,40),folderName))
{
string[] subDirectories = Directory.GetDirectories(curPath);
int count = 0;
float yOffset = .0f;
foreach(string curSubPath in subDirectories)
{
makeEvolutionSubMenu(curSubPath,count,yOffset);
yOffset = yOffset + .12f;
count = count + 1;
}
}
}
}
void makeEvolutionSubMenu(string curSubPath,int count,float yOffset)
{
List<string> subFolderNameList = new List<string>();
int n = curSubPath.Length - 1;
string subFolderName = "";
char d = ' ';
do{
subFolderName = d + subFolderName;
d = curSubPath[n];
n--;
} while (d !='/');
print (subFolderName);
subFolderNameList.Add (subFolderName);
if (GUI.Button ( new Rect(210,30+(count*50)/*Screen.height*.05f + yOffset*/,Screen.width*.1f,Screen.height*.07f),subFolderName))//GUI.Button (new Rect (Screen.width*.0f,Screen.height*(.0f+yOffset),Screen.width*.31f,Screen.height*(.30f+yOffset)),subFolderName))
{
print (subFolderName);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613141336im_/https://answers.unity.com/themes/thub/images/avi.jpg)