unity碰撞的监测和监听

ops/2025/2/9 11:44:28/

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.ppmy.cn/ops/156961.html

相关文章

redis高级数据结构布隆过滤器

文章目录 背景什么是布隆过滤器Redis 中的布隆过滤器布隆过滤器使用注意事项实现原理空间占用估计 背景 我们在使用新闻客户端看新闻时,它会给我们不停地推荐新的内容,它每次推荐时要去重,去掉那些已经看过的内容。问题来了,新闻…

DeepSeek 引发 AI 大模型战火,编程语言群雄激战谁夺胜利权杖?

随着人工智能领域的飞速发展,AI 大模型如璀璨星辰般不断涌现,DeepSeek 作为其中备受瞩目的一员,凭借其强大的性能和广泛的应用潜力吸引了众多关注。在大模型的开发与应用过程中,编程语言的选择起着至关重要的作用。 博主主页&…

2025年日祭

本文将同步发表于洛谷(暂无法访问)、CSDN 与 Github 个人博客(暂未发布) 本蒟自2025.2.8开始半停课。 任务计划(站外题与专题) 数了一下,通过人数比较高的题,也就是我准备补的题&a…

STC51案例操作

案例 1&#xff1a;LED 闪烁 功能描述&#xff1a;通过操作 P1 口寄存器&#xff0c;让连接在 P1.0 引脚的 LED 以一定间隔闪烁。 #include <reg51.h>// 延时函数 void delay(unsigned int time) {unsigned int i, j;for (i 0; i < time; i)for (j 0; j < 123; …

[Redis] Redis分布式锁与常见面试题

&#x1f338;个人主页:https://blog.csdn.net/2301_80050796?spm1000.2115.3001.5343 &#x1f3f5;️热门专栏: &#x1f9ca; Java基本语法(97平均质量分)https://blog.csdn.net/2301_80050796/category_12615970.html?spm1001.2014.3001.5482 &#x1f355; Collection与…

YOLOv11实时目标检测 | 摄像头视频图片文件检测

在上篇文章中YOLO11环境部署 || 从检测到训练https://blog.csdn.net/2301_79442295/article/details/145414103#comments_36164492&#xff0c;我们详细探讨了YOLO11的部署以及推理训练&#xff0c;但是评论区的观众老爷就说了&#xff1a;“博主博主&#xff0c;你这个只能推理…

Unity项目接入xLua的一种流程

1. 导入xlua 首先导入xlua&#xff0c;这个不用多说 2. 编写C#和Lua交互脚本 基础版本&#xff0c;即xlua自带的版本 using System.Collections; using System.Collections.Generic; using UnityEngine; using XLua; using System; using System.IO;[Serializable] public…

VSCode 换行符问题

换行符格式 在 Visual Studio Code (VSCode) 中&#xff0c;换行符问题通常涉及两种常见的换行符格式&#xff1a;CRLF&#xff08;Carriage Return Line Feed&#xff09;和 LF&#xff08;Line Feed&#xff09;。 默认情况下&#xff0c;VSCode 在不同操作系统上使用适当的…