当前位置:网站首页>Unity碰撞和触发
Unity碰撞和触发
2022-08-10 00:59:00 【是小A】
Unity碰撞条件和触发条件
- 两个物体至少有一个带有刚体
- 触发器需要在Collider组件中勾选Trigger属性
- 碰撞和被碰撞的物体都需要加有 Collider 碰撞组件
1. 碰撞器事件
//碰撞开始
public void OnCollisionEnter(Collision collision){
Debug.log(collision.name);
}
//碰撞中
public void OnCollisionStay(Collision collision){
Debug.log(collision.name);
}
//碰撞结束
public void OnCollisionExit(Collision collision){
Debug.log(collision.name);
}
2. 触发器事件
//触发开始 只调用一次
public void OnTriggerEnter(Collider collider){
Debug.log(collider.name);
}
//触发中 一直执行
public void OnTriggerStay(Collider collider){
Debug.log(collider.name);
}
//触发结束 只调用一次
public void OnTriggerExit(Collider collider){
Debug.log(collider.name);
}
人狠话不多,直接上代码,大家喜欢吗?关注加点赞,评论加收藏,下次不迷路
边栏推荐
猜你喜欢
ITK编译remote库
02| operator
Xi'an biotin-tetrapolyethylene glycol-amide-4phenol light yellow semi-solid
DHCP——动态主机配置协议
D-Biotinol Involved by Biotin, CAS No: 53906-36-8 Specific Properties Description
Unity image is blurry after using long image
数据建模已死,真的吗?
Sikuli's Automated Testing Technology Based on Pattern Recognition
[论文阅读] Multimodal Unsupervised Image-to-Image Translation
罗彻斯特大学 | 现在是什么序列?蛋白质序列的贝叶斯优化的预训练集成
随机推荐
【UNR #6 B】机器人表演(DP)
Penetration Testing and Offensive and Defense Confrontation - Vulnerability Scanning & Logic Vulnerability (Part1)
Sikuli's Automated Testing Technology Based on Pattern Recognition
小程序中计算距离信息
【Swoole系列3.5】进程池与进程管理器
Pagoda measurement - building LightPicture open source map bed system
基于设计稿识别的可视化低代码系统实践
3438. 数制转换
即时通讯开发如何撸一个WebSocket服务器
芯片资讯|半导体收入增长预计将放缓至 7%,蓝牙芯片需求依然稳步增长
将string类对象中的内容格式化到字符串Buffer中时遇到的异常崩溃分析
3511. 倒水问题
shell指定参数名传参
【kali-密码攻击】(5.1.2)密码在线破解:Medusa
Fedora 36 dnf 安装ModSecurity和 OWASP 核心规则集
Research on Ethernet PHY Chip LAN8720A Chip
Unity editor extension interface uses List
宽带由20M换为100M
头脑风暴:单词拆分
Not, even the volume of the king to write code in the company are copying and pasting it reasonable?