Use an integer as an enum?

hi, all!

I want to set up a rotation variable, but I don’t want all options available to the user. I decided 0, 30, 45, 60, and 90 would be the only available options.

I thought it would be nice to set up an enum so that in the inspector I can just pick from a pulldown menu which one I want.

However, I do not know how to link an enum to an integer value, or how to make an integer an enum.

Any tips / ideas?

Thanks!- YA

The reason enums are used so often is because they’re assigned integers internally, which makes them easy to keep track of and performant. As such, you can do this:

    public enum yourEnum 
	{
		Zero = 0,
		Thirty = 30,
		FourtyFive = 45,
		Sixty = 60,
		Ninety = 90
	}
	
	public yourEnum myEnum;

In the inspector, the user can select according to the string names, and then when you want to use it, you can simply cast the enum selection as an integer:

Debug.Log( (int)myEnum );

This Works for me:

     public enum yourEnum
     {
          _0 = 0,
          _1 = 1, 
          _2 = 2, 
          _3 = 3, 
          _4 = 4,
          _5 = 5,
          _6 = 6,
          _7 = 7,
          _8 = 8,
          _9 = 9,
          _10 = 10,
          _11 = 11,
          _12 = 12
     }