Skip to content

Instantly share code, notes, and snippets.

@BenjaminKobjolke
Last active March 24, 2021 07:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BenjaminKobjolke/9950ec26066aebd7a1803deb12973efc to your computer and use it in GitHub Desktop.
Save BenjaminKobjolke/9950ec26066aebd7a1803deb12973efc to your computer and use it in GitHub Desktop.
Cast enum #unity
int numWeapons = System.Enum.GetValues(typeof(WeaponType).Length;
// Cast weapon to int to do math on it
int wt = (int)weaponType;
wt++;
if( wt == numWeapons) wt = 0;
weaponType = (WeaponType) wt;
int numWeapons = System.Enum.GetValues(typeof(WeaponType).Length;
// Cast weapon to int to do math on it
int wt = (int)weaponType;
wt++;
if( wt == numWeapons) wt = 0;
weaponType = (WeaponType) wt;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment