Advertisement
PatchQuest

Untitled

Sep 13th, 2019
1,035
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.78 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3.  
  4. // Add this to the top object in a particle effect to make it automatically destroy when completed.
  5. // Note: Will not work if the particle system is looping.
  6.  
  7. public class ParticleSystemAutoDestructor : MonoBehaviour {
  8.  
  9.     // The particle system on this object (if one exists)
  10.     private ParticleSystem system;
  11.  
  12.     void Update () {
  13.         // Try to extract a particle system from the specified root object (First time only)
  14.         if (system == null) {
  15.             system = GetComponent<ParticleSystem> ();
  16.         }
  17.  
  18.         // Test whether the particle system should be destroyed now (Checks every frame)
  19.         if (system != null && !system.IsAlive (true)) {
  20.             Destroy (gameObject);
  21.         }
  22.     }
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement