Created
March 1, 2018 05:54
-
-
Save rawo2010/bf30863d671b773d8497a76daf5ca8b4 to your computer and use it in GitHub Desktop.
AutoDestoryPartcles
This file contains 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 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