当前位置: 首页 > news >正文

unity碰撞的监测和监听

1.创建一个地面
在这里插入图片描述
2.去资源商店下载一个火焰素材

在这里插入图片描述
3.把procedural fire导入到自己的项目包管理器中

在这里插入图片描述
4.
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碰撞监测

http://www.lryc.cn/news/534223.html

相关文章:

  • DeepSeek-R1 32B Windows+docker本地部署
  • C++11新特性之unique_ptr智能指针
  • Vue与Konva:解锁Canvas绘图的无限可能
  • python绘图之柱状堆积图的绘制
  • 剪辑学习整理
  • DeepSeek从入门到精通:全面掌握AI大模型的核心能力
  • AI大模型训练实战:分布式与微调指南
  • 整合 Redis 分布式锁:从数据结构到缓存问题解决方案
  • 并查集题目
  • 日志2025.2.9
  • 支持多种网络数据库格式的自动化转换工具——VisualXML
  • Java并发编程笔记
  • 大语言模型实践——基于现有API的二次开发
  • 获取程序运行目录 (jar运行目录)
  • Elasticsearch:如何使用 Elastic 检测恶意浏览器扩展
  • Oracle CDB自动处理表空间不足脚本
  • java-list深入理解(流程图)
  • Vue 中的 keep-alive 组件是什么?
  • 单元测试的入门实践与应用
  • 【大模型】硅基流动对接DeepSeek使用详解
  • [Windows] PDF补丁丁v1.1.0.4627绿色版
  • Oracle 变更redo log文件位置
  • 使用Redis实现业务信息缓存(缓存详解,缓存更新策略,缓存三大问题)
  • 已验证正常,Java输入字符串生成PDF文件
  • android手机安装deepseek-r1:1.5b
  • 51单片机俄罗斯方块清屏函数
  • PLSQL: 存储过程,用户自定义函数[oracle]
  • 深度学习-医学影像诊断
  • 备战蓝桥杯:双指针(滑动窗口)算法之逛花展
  • Linux如何设置软件开机启动呢?