unity 3分钟 制作粒子爆炸效果 可以用在三消消除等

思路就是:

有一个对象池,管理各种特效。

当需要播放特效时,触发如下代码:

blocker为粒子生成的位置

cs 复制代码
var particles = gamePools.iceParticlesPool.GetObject();
if (particles != null)
{
     particles.transform.position = blocker.transform.position;
     particles.GetComponent<TileParticles>().fragmentParticles.Play();
}

Prefab有两个脚本:

  1. AutoKillPooled(用途是到了时间就自杀)
cs 复制代码
    public class AutoKillPooled : MonoBehaviour
    {
        public float time = 2.0f;

        private PooledObject pooledObject;
        private float accTime;

        /// <summary>
        /// Unity's OnEnable method.
        /// </summary>
        private void OnEnable()
        {
            accTime = 0.0f;
        }

        /// <summary>
        /// Unity's Start method.
        /// </summary>
        private void Start()
        {
            pooledObject = GetComponent<PooledObject>();
        }

        /// <summary>
        /// Unity's Update method.
        /// </summary>
        private void Update()
        {
            accTime += Time.deltaTime;
            if (accTime >= time)
            {
                pooledObject.pool.ReturnObject(gameObject);
            }
        }
    }
  1. TileParticles(播放粒子)

TileParticles的脚本附在这个prefab上面,脚本内容如下:

cs 复制代码
    /// <summary>
    /// This class identifies the particles emitted when a tile entity is destroyed.
    /// </summary>
    public class TileParticles : MonoBehaviour
    {
        public ParticleSystem fragmentParticles;

        /// <summary>
        /// Unity's Awake method.
        /// </summary>
        private void Awake()
        {
            Assert.IsNotNull(fragmentParticles);
        }
    }

Fragement Particles为该prefab的子物体,上面有particles system组件。

因为particles system配置较复杂:这里直接上传prefab了

prefab下载地址

粒子prefabunity资源-CSDN文库

相关推荐
三只坚果10 小时前
blender制作动画导入unity两种方式
unity·游戏引擎·blender
benben04410 小时前
《Unity Shader入门精要》学习笔记二
unity·unity shader
YF云飞11 小时前
Unity音频管理:打造沉浸式游戏音效
游戏·unity·游戏引擎·游戏程序·个人开发
SmalBox17 小时前
【渲染流水线】[逐片元阶段]-[裁剪测试]以UnityURP为例
unity·渲染
与火星的孩子对话20 小时前
Unity高级开发:反射原理深入解析与实践指南 C#
java·unity·c#·游戏引擎·lucene·反射
scoone1 天前
开源游戏引擎Bevy 和 Godot
游戏引擎·godot
阿赵3D1 天前
Unity2022打包安卓报错的奇葩问题
android·unity·安卓
霸王•吕布1 天前
游戏引擎中的粒子系统
游戏引擎·粒子系统·粒子发射盒·粒子物理参数·粒子实例·粒子生命周期·粒子参数
小徐小徐编程不急1 天前
unity实现背包拖拽排序
unity·游戏引擎
萘柰奈2 天前
Unity进阶--C#补充知识点--【Unity跨平台的原理】Mono与IL2CPP
unity·c#·游戏引擎