Coroutines and Power Ups

In this post, I’ll briefly talk about the use of coroutines and it’s application in power up mechanics.

Unity defines coroutines as follows;

A coroutine is like a function that has the ability to pause execution and return control to Unity but then to continue where it left off on the following frame.

This comes very handy when using a constant timed event such as Power Ups.Power Ups are temporary gameplay enhancements that should change the “world” or the character in a certain time interval. That said, we first need to store the initial world settings before altering the variables. Then, we invoke the coroutine which waits about the duration of the power up and then reset the initial variables.

void ActivateTimeWarp(){
gameObject.GetComponent<PlatformerCharacter2D> ().m_MaxSpeed /= 2;
platformSpawner.GetComponent<spawnScript> ().spawnMin *= 2;
gameObject.GetComponent<PlatformerCharacter2D> ().m_JumpForce *=1.3f;
ParticleSystem tp = (ParticleSystem)Instantiate(TimeWarpParticle, transform.GetChild(0).position, Quaternion.identity);
tp.transform.parent = transform;
Snow.playbackSpeed /= 3;
StartCoroutine (DeactivateTimeWarp (tp));

}

IEnumerator DeactivateTimeWarp(ParticleSystem tp){
yield return new WaitForSeconds(15);
Destroy (tp);
gameObject.GetComponent<PlatformerCharacter2D> ().m_MaxSpeed *= 2;
platformSpawner.GetComponent<spawnScript> ().spawnMin /= 2;
gameObject.GetComponent<PlatformerCharacter2D> ().m_JumpForce /=1.3f;
Snow.playbackSpeed *= 3;
} 

It should be noted that, coroutines are still operating in the main thread and treating them as they were multi-thread solutions can be problematic. In game development, anything can happen at any time and there isn’t really a way to estimate the wide array of possibilities that the user can do. Therefore, using many coroutines are “dangerous”. In addition to that, irresponsible usages of coroutines(obvious examples such as having a constant loop, update etc.) have a direct negative impact of the devices battery (especially if you are developing for mobile devices), so use it should be used with caution.

Standard

release date

I’m excited to announce that the game will be released in late December. Everything is pretty much set up, and the game is currently in the polishing phase.

If you want to be a beta tester, you can request an invite by filling up this form.

I leave you with some screenshots.

Standard

I might be a bit late

I was thinking about creating a development blog for Mr. Chillrun for some time. The game is pretty much ready for the release and now, it seems, I might be a bit late for writing the first blog post.

Oh well, we still have a blog here right? maybe it doesn’t really matter how I implemented the Wings or the Magnet or which plugins I used while composing the theme song.

I’ll post some updates and upcoming hats in future.

Thanks, see you.

Standard