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

相关推荐
阿Q说代码10 小时前
开篇:从理论到实践,体验openEuler嵌入式开发全流程
unity·游戏引擎
zxb@hny12 小时前
Hazel游戏引擎学习
学习·游戏引擎
周小码14 小时前
Godot:10万星开源游戏引擎的硬核解析
游戏引擎·godot
qq_205279051 天前
Unity log工具 Unity Logviewer插件
unity·游戏引擎
IMPYLH1 天前
Lua 的 tonumber 函数
开发语言·笔记·后端·junit·游戏引擎·lua
tealcwu1 天前
【Unity实战】如何使用VS Code在真实iOS设备上调试 Unity应用
unity·游戏引擎·iphone
冰凌糕1 天前
Unity3D Shader 顶点和片段着色器
unity
Echo_NGC22371 天前
【AirSim 教程指南】Part 3:相机与传感器(RGB / 深度 / 分割 / LiDAR)
人工智能·计算机视觉·游戏引擎·ar·无人机·图形渲染·着色器
tealcwu1 天前
【Unity实战】如何使用VS Code在真实Android设备上调试 Unity应用
android·unity·游戏引擎
IMPYLH1 天前
Lua 的 setmetatable 函数
开发语言·笔记·后端·游戏引擎·lua