粒子系统Trigger与Collision回调函数

Trigger

回调函数:OnParticleTrigger()

粒子Trigger的检测 必须要在代码里手动给粒子系统的trigger设置一个目标碰撞体,但粒子碰到目标碰撞器的时候会进入回调函数。
设置目标碰撞器

List<ParticleSystem.Particle> enter = new System.Collections.Generic.List<ParticleSystem.Particle>();
particles.GetTriggerParticles(ParticleSystemTriggerEventType.Enter, enter);

 

 

Collision

回调函数 OnParticleCollision(GameObject other)

不需要设置目标碰撞器。
粒子碰到其他物体会调用这个回调函数。两个不一样的粒子系统的粒子互相碰撞也会发生同时回调
启用collision 会发生弹力
设置minKillSpeed 碰撞后最大灭活速度。或者设置bounce为0.或者lifetTime lose 变大。
不推荐bounce 因为粒子还会存在,只是不发生弹力

灭火案例

private void OnParticleCollision(GameObject other)
{
print(other.name);
if (count > 20)
{
GameCtrl.Instance.SwitchEvent("MieFire");

GetComponent<ParticleSystem>().loop = false;
GetComponent<ParticleSystem>().startSize /= 2;
count = -100;
GetComponent<BoxCollider>().enabled = false;
}
else
count++;
}

 

作者:Miracle
来源:麦瑞克博客
链接:https://www.playcreator.cn/archives/unity/1661/
本博客所有文章除特别声明外,均采用CC BY-NC-SA 4.0许可协议,转载请注明!
THE END
分享
海报
粒子系统Trigger与Collision回调函数
Trigger 回调函数:OnParticleTrigger() 粒子Trigger的检测 必须要在代码里手动给粒子系统的trigger设置一个目标碰撞体,但粒子碰到目标碰撞器的时候会进入……
<<上一篇
下一篇>>
文章目录
关闭
目 录