assign enum name in render

I use this enum :

enum foods{milk,juice}

i use this for show button

    for(var cnt:int=0;cnt<Enum.GetValues(typeof(foods)).Length;cnt++){
             var selectedfood:foods=cnt;}

i want when user select one on them i use selectedfood as a enum name

enum milk{x,y}

enum juice{w,z}

how can do this?

For what you’re attempting to do, I’m going to posit that Enums aren’t the right answer.

Instead, consider this:

private Dictionary<string, List<string>> foods = new Dictionary<string, List<string>>();

Then, in your relevant Start() method…

List<string> milk = new List<string>();
// ... etc ...

this.foods.Add("milk", milk);

List<string> juice = new List<string>();
// ... etc ...

this.foods.Add("juice", juice);

When you’re building the menu, the first level of items can be accessed like this:

string[] mainMenuItems = this.foods.Keys.ToArray();

Once a key is chosen (someone chooses “milk” for instance) then you can fill the list through:

List<string> submenuItems = this.foods[whichCategory];
// Loop the list and show the items.
// whichCategory would have "milk" in the case of this example.

Then, you can have rich data structures.

If you need an enum to accomany it (you have some hard-coded programming logic that uses these words as the targets of IF or SWITCH statements, for example) here’s how to get which enum value was selected from an enum:

EnumBaseName variableName = (EnumBaseName)System.Enums.Parse(typeof(EnumBaseName), valueWord);

You’d still have to use a SWITCH on the name of the enum first. (But not necessarily the value - if you use the line just posted.)

I’d start with a Toolbar or Selection Grid. Both of these can show a series of buttons, and return an index of the selected button. Then, based on the selected index you would display another toolbar or selection grid with the appropriate contents.

Example pseudo-code - note that I’m type casting the selected item from an integer to the appropriate enum.

foods selectedFood = (foods)GUI.SelectionGrid(..., array of food items, ...);

switch (selectedFood)
  case foods.milk:
    milk selectedMilk = (milk)GUI.SelectionGrid(..., array of milk items, ...);
    ... handle stuff depending on which milk is selected ...

  // additional cases for handling juice, etc.

This should give you the basic idea behind it. If you have a lot of items, or things can get nested more than a level or two deep, you would likely want to set things up in a tree or list structure, where an item has children, and those items have children, and so on. Hopefully this gets you started in the right direction though.