Unity2D碰撞,if语句

Unity2D collision, if statement

我有一点 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 中找到的当前对撞机不是脚本所在的游戏对象。

这很奇怪,因为它是对特定层的接地测试,所以接地的物体很可能不是地面的一部分。