我要用这个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 (colliders[i].gameObject != gameObject)做什么吗?
发布于 2021-07-18 18:11:08
它正在检查,以确保在重叠中找到的当前对撞机不是脚本打开的gameObject。
这是相当奇怪的,因为它是一个地面测试的一个特定的层,所以你的对象,接地最有可能不是地面的一部分。
https://stackoverflow.com/questions/68431717
复制相似问题