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文库

相关推荐
KaGme44 分钟前
生成3DGS场景在unity中的呈现
3d·unity·游戏引擎
zyh______11 小时前
关于unity的序列化
unity·游戏引擎
weixin_4093831211 小时前
godot碰撞测试的学习
学习·游戏引擎·godot
电子云与长程纠缠11 小时前
Godot学习06 - AnimationPlayer内置动画
学习·游戏引擎·godot
星夜泊客13 小时前
C# : 引用类型都存在堆上吗
unity·c#
点量云实时渲染-小芹13 小时前
Unity模型数字孪生虚拟仿真webgl推流卡实时云渲染推流
unity·webgl·数字孪生·实时云渲染·虚拟仿真·云推流
mxwin19 小时前
Unity Shader 齐次坐标与透视除法理解 SV_POSITION 的 w 分量
unity·游戏引擎·shader
NPUQS1 天前
【Unity 3D学习】Unity 与 Python 互通入门:点击按钮调用 Python(超简单示例)
学习·3d·unity
电子云与长程纠缠1 天前
Godot学习05 - 播放与分离FBX动画
学习·游戏引擎·godot
小贺儿开发1 天前
【Arduino与Unity交互探究】03 超声波测距模块
unity·arduino·串口通信·传感器·videoplayer·硬件交互