【问题标题】:Unity - Particle system - Particle countUnity - 粒子系统 - 粒子计数
【发布时间】:2018-09-30 05:08:10
【问题描述】:

有没有人知道 Unity 是否有办法计算粒子系统发射了多少粒子?所以我可以检查是否有排放,例如:

public ParticleSystem mySystem;
private int currentParticleCount;
private int lastParticleCount;

void Start () {
    lastParticleCount = mySystem.getEmissionCount();
}

void Update () {
    currentParticleCount = mySystem.getEmissionCount();
    if(currentParticleCount>lastParticleCount) {
        DoStuff();
    }
    lastParticleCount = currentParticleCount;
}

【问题讨论】:

    标签: c# unity3d particles


    【解决方案1】:

    您可以使用ParticleSystem.particleCount 返回当前的粒子数。如果这不能为您提供适当数量的粒子,请使用 ParticleSystem.GetParticles 函数,因为它只返回当前的 alive 粒子数。以下是两者的示例:

    private ParticleSystem ps;
    
    // Use this for initialization
    void Start()
    {
        ps = GetComponent<ParticleSystem>();
    }
    
    // Update is called once per frame
    void Update()
    {
        Debug.Log("Particles Count: " + ps.particleCount);
        Debug.Log("Particles Alive Count: " + GetAliveParticles());
    }
    
    int GetAliveParticles()
    {
        ParticleSystem.Particle[] particles = new ParticleSystem.Particle[ps.particleCount];
        return ps.GetParticles(particles);
    }
    

    【讨论】:

      【解决方案2】:

      您要求的确切功能不是构建它,而是:

      您可以知道系统显示的当前粒子,因此您可以制作一个累积数字的计数器,或者如果您知道“显示时间”,您可以进行数学运算。

      了解当前粒子: ParticleSystem.particleCounthttps://docs.unity3d.com/ScriptReference/ParticleSystem-particleCount.html

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-02-09
        • 2010-11-30
        • 1970-01-01
        • 1970-01-01
        • 2019-07-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多