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

相关推荐
databook8 小时前
探索视觉的边界:用 Manim 重现有趣的知觉错觉
python·动效
databook5 天前
ManimCE v0.20.1 发布:LaTeX 渲染修复与动画稳定性提升
python·动效
爱搞虚幻的阿恺9 天前
Niagara粒子系统-超炫酷的闪电特效(加餐 纸牌螺旋上升效果)
游戏·游戏引擎
_Li.9 天前
Simulink - 6DOF (Euler Angles)
人工智能·算法·机器学习·游戏引擎·cocos2d
weixin_424294679 天前
Unity 调用Steamworks API 的 SteamUserStats.RequestCurrentStats()报错
unity·游戏引擎·steamwork
HoFunGames9 天前
Unity小地图,Easy Minimap System MT-GPS插件
unity·游戏引擎
wy3258643649 天前
Unity 新输入系统InputSystem(基本操作)
unity·c#·游戏引擎
WarPigs9 天前
着色器multi_compile笔记
unity·着色器
ECHO飞跃 0129 天前
Unity2019 本地推理 通义千问0.5-1.5B微调导入
人工智能·深度学习·unity·llama
Unity游戏资源学习屋9 天前
【Unity UI资源包】GUI Pro - Casual Game 专为休闲手游打造的专业级UI资源包
ui·unity