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

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 created
    void Start()
    {

    }

    // Update is called once per frame
    void 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 created
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        timer += Time.deltaTime;
        if (timer > 1)
        {
            Destroy(gameObject);
        }
    }
}

运行结果

untiy 3D碰撞监测


http://www.kler.cn/a/542308.html

相关文章:

  • 长安链支撑全国不动产登记数据可信流通
  • 【C#零基础从入门到精通】(九)——C#if和Switch判断语句详解
  • 【目标检测xml2txt】label从VOC格式xml文件转YOLO格式txt文件
  • 前端开发中,如何判断一个元素是否在可视区域中?
  • 【前端开发】HTML+CSS+JavaScript前端三剑客的基础知识体系了解
  • 2月10日QT
  • SpringBoot 项目中使用Log4j2详细(避坑)
  • 在Uniapp中使用阿里云OSS插件实现文件上传
  • 高级java每日一道面试题-2025年02月03日-服务器篇[Nginx篇]-Nginx是如何处理一个HTTP请求的呢 ?
  • 【leetcode】滑动窗口刷题总结
  • Python 爬虫基础教程
  • 物联网水质监测系统设计与实现/基于STM32的水产养殖云监控系统设计
  • Kubernetes 最佳实践:Top 10 常见 DevOps/SRE 面试问题及答案
  • Java、Go、Rust、Node.js 的内存占比及优缺点分析
  • DeepSeek投喂数据(训练AI)
  • DeepSeek模拟阿里面试——Mysql
  • Linux性能优化实战:从CPU到磁盘I/O
  • FFmpeg + OpenGL ES 美颜相机教程大纲
  • jupyter notebook中3种读图片的方法_与_图片翻转(上下翻转,左右翻转,上下左右翻转)
  • 【Django】 templates模板与static静态文件
  • oa二开问题
  • ①电视盒子刷linux系统之armbian
  • vue3: 通过template解析渲染
  • 第四篇:放大电路的“子弹时间”——车载音频与传感器信号链设计
  • 重庆西站公路桥梁自动化监测
  • Ansible内置模块之cron