有人知道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;
}发布于 2018-09-30 17:26:55
可以使用ParticleSystem.particleCount返回当前的粒子数。如果这没有提供适当数量的粒子,请使用ParticleSystem.GetParticles函数,因为该函数仅返回当前活动粒子的数量。下面是它们的一个示例:
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);
}发布于 2018-09-30 17:28:08
您要求的确切功能不是构建它,而是:
你可以知道系统显示的当前粒子,所以你可以制作一个计数器来累计数字,或者如果你知道“显示时间”,你可以做数学计算。
了解当前粒子:ParticleSystem.particleCount https://docs.unity3d.com/ScriptReference/ParticleSystem-particleCount.html
https://stackoverflow.com/questions/52574831
复制相似问题