Quantcast
Viewing latest article 17
Browse Latest Browse All 49

Code structure for power ups

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.

Viewing latest article 17
Browse Latest Browse All 49

Trending Articles