1、创建新项目
2、导入素材
Unity Particle Pack | Tutorial Projects | Unity Asset Store
3、场景中创建一个物体
4、 给球体添加一个新脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Boom : MonoBehaviour
{
public float delay = 3f;//爆炸前延时时间
float countdown;//倒计时
bool hasExploded = false;//确认是否爆炸
public GameObject explosionEffect;
void Start()
{
countdown = delay;
}
// Update is called once per frame
void Update()
{
countdown -= Time.deltaTime;
if (countdown <= 0f&&!hasExploded)
{
Explode();
hasExploded = true;
}
}
//爆破函数
void Explode()
{
//显示爆炸效果
Instantiate(explosionEffect, transform.position, transform.rotation);//实例化爆炸效果
Destroy(gameObject);
}
}
5、添加爆炸粒子
6、取消循环播放
最终效果
参考视频: