Skip to content

Instantly share code, notes, and snippets.

@JonathanYin
Created July 20, 2017 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonathanYin/2ac7ae45905fffa318dc0c68e2dad2f9 to your computer and use it in GitHub Desktop.
Save JonathanYin/2ac7ae45905fffa318dc0c68e2dad2f9 to your computer and use it in GitHub Desktop.
using UnityEngine;
public class SpecialEffectsHelper : MonoBehaviour
{
public static SpecialEffectsHelper Instance;
public ParticleSystem smokeEffect;
public ParticleSystem fireEffect;
void Awake()
{
// Register the singleton
if (Instance != null)
{
Debug.LogError("Multiple instances of SpecialEffectsHelper!");
}
Instance = this;
}
public void Explosion(Vector3 position)
{
// Smoke on the water
instantiate(smokeEffect, position);
// Fire in the sky
instantiate(fireEffect, position);
}
private ParticleSystem instantiate(ParticleSystem prefab, Vector3 position)
{
ParticleSystem newParticleSystem = Instantiate(
prefab,
position,
Quaternion.identity
) as ParticleSystem;
// Make sure it will be destroyed
Destroy(
newParticleSystem.gameObject,
newParticleSystem.startLifetime
);
return newParticleSystem;
}
}
@JonathanYin
Copy link
Author

This script is attached to the Main Camera, and is used to instantiate and destroy the particle effects that I use in my game. In my enemy/obstacle scripts, I call this script before destroying the player in order to create an explosion effect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment