1.创建一个地面
2.去资源商店下载一个火焰素材
3.把procedural fire导入到自己的项目包管理器中
4.给magic fire 0 挂在碰撞组件Rigidbody , Sphere Collider
5.创建脚本test 并挂在magic fire 0
脚本代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class test : MonoBehaviour
{// 创建 一个爆炸的预设体public GameObject Prefab;// Start is called once before the first execution of Update after the MonoBehaviour is createdvoid Start(){}// Update is called once per framevoid Update(){}// 监听发生碰撞private void OnCollisionEnter(Collision collision){// 创建一个爆炸物体Instantiate(Prefab, transform.position, Quaternion.identity);// 销毁自身Destroy(gameObject);}// 持续碰撞中private void OnCollisionStay(Collision collision){}// 结束碰撞private void OnCollisionExit(Collision collision){}}
6.把explosion 加到test 脚本的预制件
7.创建碰撞销毁脚本BZ,并挂在到EXPLOSION
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class bz : MonoBehaviour
{float timer = 0;// Start is called once before the first execution of Update after the MonoBehaviour is createdvoid Start(){}// Update is called once per framevoid Update(){timer += Time.deltaTime;if (timer > 1){Destroy(gameObject);}}
}
运行结果
untiy 3D碰撞监测