How can I cycle through sprites on button presses (C#)?

Hello!

I am working on a top down, 8 directional movement where the player is constantly moving forward, and pressing left and right arrow keys rotate the player 45 degrees and change the sprite to a new one matching the new direction. How can the sprite cycle be done? I’ve tried true/false values but they cycle through all at once without stopping, and I’ve tried floats but I can’t add a value to a float that applies to the animator for some reason. Pressing right or left should cause a sprite to switch just once, and pressing again would switch to a new sprite, while pressing left would bring back the previous sprite. I’m completely new to C# so any advice will help.

Thanks!!

I would suggest using an animator and a sprite sheet. You are going to want to load all of your 8 sprites into a sprite sheet and then import that into Unity. Once imported you are going to want to create a state for each sprite direction. Set a variable to control which state you want to fire on button press to change the sprite.