You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

32 lines
732 B

using UnityEngine;
using System.Collections;
[RequireComponent(typeof(ParticleSystem))]
public class AutoDestroyParticle : MonoBehaviour
{
[SerializeField] private bool onlyDeactivate;
[SerializeField] private float destoryPlusTime;
[SerializeField] private ParticleSystem particle;
private void Awake()
{
particle = GetComponent<ParticleSystem>();
}
void OnEnable()
{
if (onlyDeactivate)
{
Invoke(nameof(DisableSelf), particle.main.duration + destoryPlusTime);
}
else
{
Destroy(gameObject, particle.main.duration + destoryPlusTime);
}
}
void DisableSelf()
{
gameObject.SetActive(false);
}
}