change enum state with keypress

i have this function for setting bullet types through an enum.

public void SetBulletType(BulletTypes type)
    {
        sprite.sprite = bulletData[(int)type].sprite;
        cc2d.radius = bulletData[(int)type].radius;
        transform.localScale = bulletData[(int)type].scale;
    }

and i have this function in my player controller for shooting the bullets

 bullet.GetComponent<BulletScript>().SetBulletType(BulletScript.BulletTypes.Default);

how can i create a function that changes the bullet type with a keypress??

Look up Unity UI tutorials for connecting functions to buttons, then connect appropriately.

6855701--798845--Screen Shot 2021-02-19 at 7.29.44 AM.png

oh i meant button press! not ui buttons! like cycle through the enum on keypress

i want to make a weapon system and since my bullet script has a few different types of bullets , at least colors and sprites i was wondering if i could change the type with a keypress in the game.

public enum BulletTypes { Default, MiniBlue, MiniGreen, MiniOrange, MiniPink, MiniRed ,Charged};

    [SerializeField] BulletTypes bulletType = BulletTypes.Default;

https://docs.unity3d.com/ScriptReference/Input.GetKeyDown.html

yeah thanks but again not what i asked! or maybe i asked wrong! sorry if thats the case. just how to cycle through the enum with getkeydown!

If the enums are sequential, just increment them as if they’re an integer.

When they reach the last one, cycle it back to the first.

If the enums are not sequential, put them into an array, keep an index, cycle the index through the array.

oh thanks!!

I usually write all my enums like this:

public enum BulletType
{
 BB,
 Pistol,
 Rifle,
 Shotgun,
 // insert all new items here
 MAXIMUM,
};

Then I know what the last one is.

private BulletType bulletType;

to increment:

bulletType++;
// wrap?
if (bulletType >= BulletType.MAXIMUM)
{
  bulletType = 0;
}

wow great! i though of doing a for loop but this one is just the thing i needed!