I’m creating a simulation that allows the user to select items from a 3D product catalogue. I’ve set up a series of arrays that sorts unique and identical items into groups with a text field where a price can be added to calculate some totals. My problem is that a user can select any number of items, even hundreds if they so choose. Is there a way to adjust the number of text fields based on the number of items chosen? Right now I’m using a finite switch statement:
function GUITextFieldSwitcher(){
GUILayout.BeginVertical();//End the automatic vertical layout
GUILayout.BeginHorizontal();//End the automatic horizontal layout
switch (i7) {
case 0 :
stringToEdit0 = GUILayout.TextField (stringToEdit0, 5, GUILayout.Width(50));
GUILayout.Label("
“+” “+PriceCalc00.ToString(), mySkin20);
var temp0 : float = 0.0f;
if (stringToEdit0 != “”){
if (float.TryParse(stringToEdit0, temp0)){
PriceCalc00 = Mathf.Clamp(0.00, temp0, PriceCalc00) * pickDuplicateNumber;
}
}
break;
case 1 :
stringToEdit1 = GUILayout.TextField (stringToEdit1, 5, GUILayout.Width(50));
GUILayout.Label(”
“+” "+PriceCalc01.ToString(), mySkin20);
var temp1 : float = 0.0f;
if (stringToEdit1 != “”){
if (float.TryParse(stringToEdit1, temp1)){
PriceCalc01 = Mathf.Clamp(0.00, temp1, PriceCalc01) * pickDuplicateNumber;
}
}
break;
etc, etc, etc. This approach would require a case for each possible item and, therefore, a unique text field variable for each, otherwise the user can’t type in unique prices in each field. Is there a way to create text fields on the fly so that I don’t have to set up such an immense switch statement?