ParticleEffectForUGUI icon indicating copy to clipboard operation
ParticleEffectForUGUI copied to clipboard

Control particle position form script.

Open GabrielCoriiu opened this issue 1 year ago • 3 comments

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 avatar Jan 05 '24 18:01 GabrielCoriiu

@GabrielCoriiu Thank you for the feature request!

mob-sakai avatar Jan 06 '24 00:01 mob-sakai

@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);
    }
}

mob-sakai avatar Jan 23 '24 12:01 mob-sakai

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.

GabrielCoriiu avatar Jan 23 '24 12:01 GabrielCoriiu

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.

mob-sakai avatar May 22 '24 08:05 mob-sakai