c# - Unity2D 碰撞,if 语句
问题描述
我有一点 unityCode 来检查角色是否接地
private void FixedUpdate(){
is_on_ground = false;
// The player is grounded if a circlecast to the groundcheck position hits anything designated as ground
// This can be done using layers instead but Sample Assets will not overwrite your project settings.
Collider2D[] colliders = Physics2D.OverlapCircleAll(m_GroundCheck.position, k_GroundedRadius, m_WhatIsGround);
for (int i = 0; i < colliders.Length; i++) {
if (colliders[i].gameObject != gameObject) {
is_on_ground = true;
}
}
}
有人可以解释 if 语句的if (colliders[i].gameObject != gameObject)
作用吗?
解决方案
它正在检查以确保在 Overlap 中找到的当前对撞机不是脚本所在的游戏对象。
这很奇怪,因为它是对特定层的接地测试,因此接地的对象很可能不属于地面。
推荐阅读
- javascript - 在移动设备上放大时如何删除页面下的空白
- kerberos - SSPI 意外地为具有相同密码的帐户进行身份验证
- php - 将 PHP 表单连接到 MySQL 问题
- c - 我可以使用标记粘贴来处理编译时命名吗?
- api - 内部 API 无法通过内部 APIGEE 访问
- python - python中的subprocess.call()是用来做什么的?
- ios - iOS Facebook 登录在升级到 5 后无法正常工作
- android - 通过数据绑定中的变量标签设置文本大小
- php - Wordpress 将自定义键和值添加到 wp_query 响应
- react-hooks - 为什么`react-hooks/exhaustive-deps` lint 规则会在嵌套对象属性上触发?