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

52 lines
1.2 KiB
C#

3 years ago
using System.Linq;
using System.Text;
using UnityEngine;
using System.Collections;
public class FadeInOutParticles : MonoBehaviour {
private EffectSettings effectSettings;
private ParticleSystem[] particles;
private bool oldVisibleStat;
private void GetEffectSettingsComponent(Transform tr)
{
var parent = tr.parent;
if (parent != null)
{
effectSettings = parent.GetComponentInChildren<EffectSettings>();
if (effectSettings == null)
GetEffectSettingsComponent(parent.transform);
}
}
void Start()
{
GetEffectSettingsComponent(transform);
particles = effectSettings.GetComponentsInChildren<ParticleSystem>();
oldVisibleStat = effectSettings.IsVisible;
}
void Update()
{
if (effectSettings.IsVisible!=oldVisibleStat) {
if (effectSettings.IsVisible)
foreach (var particle in particles) {
if (effectSettings.IsVisible) {
particle.Play();
particle.enableEmission = true;
}
}
else
foreach (var particle in particles) {
if (!effectSettings.IsVisible) {
particle.Stop();
particle.enableEmission = false;
}
}
}
oldVisibleStat = effectSettings.IsVisible;
}
}