欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > IT业 > untiy3d 触发和碰撞区别

untiy3d 触发和碰撞区别

2025/2/13 18:12:41 来源:https://blog.csdn.net/weixin_50379372/article/details/145550480  浏览:    关键词: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 createdvoid Start(){}// Update is called once per framevoid 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 createdvoid Start(){}// Update is called once per framevoid 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 触发碰撞

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com