ParticleEffectForUGUI
ParticleEffectForUGUI copied to clipboard
Control particle position form script.
Hi,
This is a very nice project. Is there a way to create custom scripts for controlling the particles' position (and maybe some other properties)? I've tried subscribing to Canvas.willRenderCanvases, Canvas.preWillRenderCanvases as well as Update() and LateUpdate(), but none of them seems to be working. I checked how UIParticleAttractor works but it seems to be part of a closed system.
@GabrielCoriiu Thank you for the feature request!
@GabrielCoriiu
For example, the following component moves particles on Update. It works.
using UnityEngine;
[ExecuteAlways]
[RequireComponent(typeof(ParticleSystem))]
public class ParticleMovement : MonoBehaviour
{
public ParticleSystem m_ParticleSystem;
public Vector3 m_Move = Vector3.zero;
private static readonly ParticleSystem.Particle[] s_Particles = new ParticleSystem.Particle[1024];
private void Update()
{
if (!m_ParticleSystem || !m_ParticleSystem.IsAlive()) return;
var count = m_ParticleSystem.particleCount;
m_ParticleSystem.GetParticles(s_Particles);
for (var i = 0; i < count; i++)
{
s_Particles[i].position += m_Move * Time.deltaTime;
}
m_ParticleSystem.SetParticles(s_Particles, count);
}
}
Thanks, I'll try it out. I only tried it from a component that was not attached to the same game object as the particle system, but a parent of it.
Since there has been no new discussion for a long time, this issue was closed. If the same issue arises, please re-open this issue.