Skip to content

Instantly share code, notes, and snippets.

@rawo2010
Created March 1, 2018 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rawo2010/bf30863d671b773d8497a76daf5ca8b4 to your computer and use it in GitHub Desktop.
Save rawo2010/bf30863d671b773d8497a76daf5ca8b4 to your computer and use it in GitHub Desktop.
AutoDestoryPartcles
using UnityEngine;
using System.Collections.Generic ;//Use :System.Collections.Generic.List<>.
//ChildrenのDurationにも対応したパーティクル自動削除スクリプト
[RequireComponent(typeof(ParticleSystem))]
public class AutoDestoryPartcles : MonoBehaviour {
// Use this for initialization
void Start () {
List<ParticleSystem> partcleSystems = new List<ParticleSystem>();
//ゲームオブジェクトにアタッチされているParticleSystemを追加.
partcleSystems.Add(GetComponent<ParticleSystem>() ) ;
partcleSystems.AddRange(GetComponentsInChildren<ParticleSystem>() ) ;
float LongestDuration = 0 ;
//Listに入っている分、Durationを比較して、その中の一番大きい数を代入
foreach(ParticleSystem partcle in partcleSystems){
if(partcle.main.duration > LongestDuration){
LongestDuration = partcle.main.duration ;
}
}
//duration(=存続期間)が経過したらオブジェクトを削除
Destroy(gameObject, LongestDuration ) ;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment