I'm trying to create a weapon script for the player. I decided dump the different weapons/objects into and enum rather than using a SwitchWeapon function. However, now I'm kind of stuck. I would like to add the feature of using either the mouse scroll or the "q" and "e" keys to cycle between the weapons. I know exactly how I would do it had I created a weapon function, however I'm kind of at a loss for how to do this with an enum and I really don't feel like starting the script over using a weapon function. I suppose I could use a series of if else statements to check which WeaponType from the list is selected, but it seems like there should be a more intuitive way to do this.
Also, I'm not terribly familiar with using enum (obviously). Does the enum have integers corresponding to each element in the list? because then I suppose I could just increase/decrease that integer by one.
Here's some of the code I have:
The enum:
enum WeaponType {primaryFire, concreteBarrier, stationaryTurret, playerShield};
var weaponType : WeaponType;
//this is sent to a switch(weaponType) case
if(Input.GetKeyDown("f")){
weaponType = WeaponType.primaryFire;
}
if(Input.GetKeyDown("1")){
weaponType = WeaponType.concreteBarrier;
}
if(Input.GetKeyDown("2")){
weaponType = WeaponType.stationaryTurret;
}
if(Input.GetKeyDown("3")){
weaponType = WeaponType.playerShield;
}
if(Input.GetKeyDown("e")){
//what code needs to go here to switch to the next weapon/object in the enum list?
}
if(Input.GetKeyDown("q")){
//what code needs to go here to switch to the previous weapon/object in the enum list?
}
Sorry this is so long. Thanks for any help in advance.