Advertisement
johnnygoodguy2000

DestroyFinishedPartical.cs

Apr 27th, 2024 (edited)
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.68 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class DestroyFinishedPartical : MonoBehaviour
  6. {
  7.     private ParticleSystem thisParticleSystem;
  8.     // Start is called before the first frame update
  9.     void Start()
  10.     {
  11.         thisParticleSystem = GetComponent<ParticleSystem>();
  12.     }
  13.  
  14.     // Update is called once per frame
  15.     void Update()
  16.     {
  17.        
  18.         if (!thisParticleSystem.isPlaying)
  19.         {
  20.            
  21.             if (gameObject == null) return;// Check if the game object is null
  22.  
  23.             Destroy (gameObject);
  24.         }
  25.     }
  26.  
  27.     void OnBecameInvisible()
  28.     {
  29.         Destroy(gameObject);
  30.     }
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement