I’m struggling to create code for a game I’m working on that includes power ups. When the player picks up a power up, I need to start a new power up progress bar, and activate the power up. After the progress bar ends, it should disappear and whatever property was changed by the power up should reset (perhaps the time scale, or gravity). To complicate matters, if I run a reset game function, it should reset all of these global properties and end all associated coroutines (otherwise I may reset a global variable and change it before the coroutine ends and then resets it a second time - I’ve had this happen before).
The issue I’m having is that I’ve set up a coroutine for the progress bar in my UI Controller script and I’ve set up power up action coroutines in my Game Controller script (they change a global variable, wait so many seconds, then change it back). However, if I activate them from the power up script using a StartCoroutine function right before I destroy the power up, they don’t run. This means creating a second function in each controller script that exists purely to start a coroutine for the other function. And I’m not sure how to cut these coroutines short to reset my game.
Any help would be appreciated.
So instead of calling/starting a game controller coroutine in the power up script, my best option is to call a function in the game controller that starts the game controller coroutine? It just feels more complicated than it should be.
I guess on resets I could use the stop all coroutines option and then search for any progress bars and remove them, but this feels like the nuclear option.