Created
July 20, 2017 16:15
-
-
Save JonathanYin/2ac7ae45905fffa318dc0c68e2dad2f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.