在 Unity 中播放粒子系统 [英] playing particle system in Unity

查看:34
本文介绍了在 Unity 中播放粒子系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Unity3D 为使用 SteamVR 的 HTV Vive 进行开发.我已经从资产商店下载了使用粒子系统创建的爆炸效果的资产.我想在对象被破坏时播放粒子动画.这是我使用的代码,但未成功.

I am using Unity3D to develop for the HTV Vive using SteamVR. I have downloaded an asset from the asset store with explosion effect created using a particle system. I want to play the particle animation when an object is destroyed. Here is the code I am, unsuccessfully, using.

private void OnDestroy() {
    explosion.GetComponent<ParticleSystem>().Play();
}

Explosion 是从检查器设置的 GameObject 类型的公共变量.我将粒子系统对象放在那里.

Explosion is a public variable of type GameObject set from the inspector. I drop the particle system object there.

为什么它不起作用?任何关于学习使用(而不是创建)粒子效果的简短教程的好建议?

Why is it not working? anyone a good recommendation on a short tutorial to learn to use (not to create) particle effects?

谢谢

层次结构视图

我已经将 PS 作为目标的子对象和独立对象进行了尝试.

I have tried this with the PS as a child of the target and as an independent object.

检查员(目标)的视图

检查器视图(粒子系统)

view of the inspector (particle system)

由于某种原因,粒子效果在场景开始后立即被破坏.

edit: for some reason, the particle effect is destroyed right after the scene starts.

推荐答案

尝试将爆炸效果制作成预制件,并在销毁时实例化.

Try making the explosion effect into a prefab and instantiate it when destroyed.

GameObject explosion; // Prefab asset
private void OnDestroy() {
    Instantiate(explosion, transform.position, Quaternion.identity);
}

另外,不要忘记破坏的停止动作.

Also, don't forget the stop action to Destroy.

这篇关于在 Unity 中播放粒子系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆