How do I turn on and off 2d animations using code?

How do I turn on and off the 2d sprite renderer for an animation using key pressed?
So for my project I have a 2d sprite animation running on the background. I want to make it so when a key is pressed on the keyboard, the sprite turns invisible but can be turned back on later. I don’t know how to do this. Please help.

If it’s just completely disappeaing then you could just set it’s active state to off. IF you’re making it invisible but it’s like translucent you could adjust it’s alpha. The active state is probably the easiest change.