My attempt at the Lazer Defender explosion VFX

4r1u9i

So I know its not a particle effect but i wanted my ship explosion’s to have a kind of old school feel, so instead i created a new game object and added a sprite array to it and built a coroutine to control the timing on how it cycles through the sprites then I linked the explosion to the player and enemy prefabs and when they die i instantiated the explode gameObject and then after its done in the coroutine it deletes itself.

Im actually really excited about this as it was the first time i really thought through and made a change in these trainings to make the game logic more of my creation :slight_smile:

5 Likes

here is the code to how i did it, let me know if there is a cleaner way to write it

public class Explosion : MonoBehaviour
{

[SerializeField] Sprite[] explosionSprites;
[SerializeField] float explosionTransitionTime = .5f;
int i = 0;

SpriteRenderer explosionSpriteRenderer;


// Start is called before the first frame update
void Start()
{
    explosionSpriteRenderer = gameObject.GetComponent<SpriteRenderer>();
    StartCoroutine(explode()); 
    
}

IEnumerator explode()
{
    while (i < explosionSprites.Length)
    {
        explosionSpriteRenderer.sprite = explosionSprites[i];
        i++;
        yield return new WaitForSeconds(explosionTransitionTime);
    }
    Destroy(gameObject);

}
4 Likes

Privacy & Terms