36 lines
826 B
C#
36 lines
826 B
C#
using UnityEngine;
|
|
|
|
[RequireComponent(typeof(ParticleSystem))]
|
|
public class infiniteParticleLifeSM : MonoBehaviour
|
|
{
|
|
private ParticleSystem m_System;
|
|
|
|
private ParticleSystem.Particle[] m_Particles;
|
|
|
|
private void LateUpdate()
|
|
{
|
|
InitializeIfNeeded();
|
|
int particles = m_System.GetParticles(m_Particles);
|
|
for (int i = 0; i < m_Particles.Length; i++)
|
|
{
|
|
if (m_Particles[i].remainingLifetime <= 0.1f)
|
|
{
|
|
m_Particles[i].remainingLifetime = m_Particles[i].startLifetime;
|
|
}
|
|
}
|
|
m_System.SetParticles(m_Particles, particles);
|
|
}
|
|
|
|
private void InitializeIfNeeded()
|
|
{
|
|
if (m_System == null)
|
|
{
|
|
m_System = GetComponent<ParticleSystem>();
|
|
}
|
|
if (m_Particles == null || m_Particles.Length < m_System.main.maxParticles)
|
|
{
|
|
m_Particles = new ParticleSystem.Particle[m_System.main.maxParticles];
|
|
}
|
|
}
|
|
}
|