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

相关推荐
心疼你的一切2 小时前
Unity异步编程神器:Unitask库深度解析(功能+实战案例+API全指南)
深度学习·unity·c#·游戏引擎·unitask
呆呆敲代码的小Y4 小时前
【Unity 实用工具篇】 | Book Page Curl 快速实现翻书效果
游戏·unity·游戏引擎·u3d·免费游戏·翻书插件
AC梦17 小时前
unity中如何将UI上的字高清显示
ui·unity
小贺儿开发1 天前
Unity3D 智慧城市管理平台
数据库·人工智能·unity·智慧城市·数据可视化
June bug2 天前
【领域知识】休闲游戏一次发版全流程:Google Play + Apple App Store
unity
星夜泊客2 天前
C# 基础:为什么类可以在静态方法中创建自己的实例?
开发语言·经验分享·笔记·unity·c#·游戏引擎
dzj20212 天前
PointerEnter、PointerExit、PointerDown、PointerUp——鼠标点击物体,则开始旋转,鼠标离开或者松开物体,则停止旋转
unity·pointerdown·pointerup
心前阳光2 天前
Unity 模拟父子关系
android·unity·游戏引擎
在路上看风景2 天前
26. Mipmap
unity
咸鱼永不翻身2 天前
Unity视频资源压缩详解
unity·游戏引擎·音视频