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

untiy3d 触发和碰撞区别

1.创建一个地面。一个两个立方体,一个胶囊
在这里插入图片描述
2.给胶囊加一个刚体组件
在这里插入图片描述
3.给胶囊加 一个角色控制的脚本
在这里插入图片描述

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NEW : MonoBehaviour
{
    // 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()
    {
        // 水平轴
        float horizontal = Input.GetAxis("Horizontal");
        // 垂直轴
        float vertical = Input.GetAxis("Vertical");
        // 向量
        Vector3 dir = new Vector3(horizontal, 0, vertical);
        // 朝向范方向移动
        transform.Translate(dir * 2 * Time.deltaTime);



    }
}

4.把触发区立方体设置成是触发器
在这里插入图片描述
5.编写触发脚本并挂在到触发区juxing上

在这里插入图片描述

using System.Xml.Linq;
using UnityEngine;

public class PZ : MonoBehaviour
{
    // 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 OnTriggerEnter(Collider other)
    {
        // 获取墙的物体
        GameObject qiang = GameObject.Find("qang");
        if (qiang !=null) {
            qiang.SetActive(false);
        }

    }
    // 触发中
    private void OnTriggerStay(Collider other)
    {
        
    }

    // 触发结束

    private void OnTriggerExit(Collider other)
    {
        
    }

运行结果
当用键盘的wasd键控制胶囊到juxing触发区时,qiang消失

untiy 触发碰撞


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

相关文章:

  • innovus如何分步长func和dft时钟
  • MacBook Pro M2安装deepseek
  • C++20 新特性解析
  • 科技查新要怎么做
  • 链表分割-双哨兵位
  • Python 查看各个库的版本
  • DotNet5在Docker中连接SqlServer2012,报错最大池超出
  • 【数据迁移】- Oracle GoldenGate(OGG)
  • 设计模式中的关联和依赖区别
  • ASP.NET Core 外部向SignalR的Hub发消息
  • MT6835 21位 磁编码器 SPI 平台无关通用驱动框架 STM32
  • 3.4 学习UVM中的uvm_monitor类分为几步?
  • 【论文笔记】Are Self-Attentions Effective for Time Series Forecasting? (NeurIPS 2024)
  • 移植BOA服务器到GEC2440开发板
  • 图解72个机器学习基础知识点
  • Flink怎么保证Exactly - Once 语义
  • 大型语言模型(LLM)中的自适应推理预算管理:基于约束策略优化的解决方案
  • 人工智能与低代码如何重新定义企业数字化转型?
  • Windows11系统笔记本电脑真的关机了么
  • Ubuntu指令学习(个人记录、偶尔更新)