首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >单位-粒子系统-粒子计数

单位-粒子系统-粒子计数
EN

Stack Overflow用户
提问于 2018-09-30 13:08:10
回答 2查看 1.7K关注 0票数 1

有人知道Unity是否有一种方法来计算粒子系统已经发射了多少粒子?因此,我可以检查是否有发射,例如:

代码语言:javascript
复制
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;
}
EN

回答 2

Stack Overflow用户

发布于 2018-09-30 17:26:55

可以使用ParticleSystem.particleCount返回当前的粒子数。如果这没有提供适当数量的粒子,请使用ParticleSystem.GetParticles函数,因为该函数仅返回当前活动粒子的数量。下面是它们的一个示例:

代码语言:javascript
复制
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
EN

Stack Overflow用户

发布于 2018-09-30 17:28:08

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

你可以知道系统显示的当前粒子,所以你可以制作一个计数器来累计数字,或者如果你知道“显示时间”,你可以做数学计算。

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52574831

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档