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.
CrowdControl/Assets/Feel/MMTools/Tools/MMParticles/MMDelayParticles.cs

52 lines
1.3 KiB
C#

2 months ago
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace MoreMountains.Tools
{
[ExecuteAlways]
/// <summary>
/// MM delay particles.
/// </summary>
[AddComponentMenu("More Mountains/Tools/Particles/MMDelayParticles")]
public class MMDelayParticles : MonoBehaviour
{
[Header("Delay")]
/// the duration of the delay, in seconds
public float Delay;
/// if this is true, this will delay by the same amount all children particle systems of this object
public bool DelayChildren = true;
/// if this is true, the delay will be applied on Start
public bool ApplyDelayOnStart = false;
[MMInspectorButtonAttribute("ApplyDelay")]
public bool ApplyDelayButton;
protected Component[] particleSystems;
protected virtual void Start()
{
if (ApplyDelayOnStart)
{
ApplyDelay();
}
}
protected virtual void ApplyDelay()
{
if (this.gameObject.GetComponent<ParticleSystem>() != null)
{
ParticleSystem.MainModule main = this.gameObject.GetComponent<ParticleSystem>().main;
main.startDelay = main.startDelay.constant + Delay;
}
particleSystems = GetComponentsInChildren<ParticleSystem>();
foreach (ParticleSystem system in particleSystems)
{
ParticleSystem.MainModule main = system.main;
main.startDelay = main.startDelay.constant + Delay;
}
}
}
}