Created
January 10, 2020 10:44
-
-
Save wakeup5/db3b3b84c258514410474c8dc017d9a4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class ParticleSystemLifetime : MonoBehaviour | |
{ | |
public enum Action | |
{ | |
Disable, | |
Destroy | |
} | |
[SerializeField] | |
public Action action; | |
private ParticleSystem ps; | |
private void Awake() | |
{ | |
ps = GetComponent<ParticleSystem>(); | |
} | |
private void OnEnable() | |
{ | |
ps.Play(); | |
StartCoroutine(nameof(DoActionAfterLifetime)); | |
} | |
private void OnDisable() | |
{ | |
StopCoroutine(nameof(DoActionAfterLifetime)); | |
} | |
private IEnumerator DoActionAfterLifetime() | |
{ | |
yield return new WaitForSeconds(ps.main.duration); | |
switch (action) | |
{ | |
case Action.Disable: | |
gameObject.SetActive(false); | |
break; | |
case Action.Destroy: | |
Object.Destroy(gameObject); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment