///


/// 射线检测
///

/// 自身位置偏移量(检测起始点)
/// 射线方向
/// 射线长度(检测距离)
/// 检测层级
///
public RaycastHit2D Raycast(Vector2 offset,Vector2 rayDiraction,float length,LayerMask layer)
{
RaycastHit2D hit = Physics2D.Raycast((Vector2)transform.position + offset, rayDiraction, length, layer);
Color color = hit? Color.green : Color.red;//hit可作为bool值检测到时为:TRUE,未检测到为:false
Debug.DrawLine((Vector2)transform.position + offset, (Vector2)transform.position + offset+rayDiraction*0.2f, color);
Debug.DrawLine(transform.position, offset,Color .blue);//锚点位置在图像下边中点。
return hit;
}
//--------------------------------------------------------------------
//线检测
enemyCl.enabled = false;
RaycastHit2D hit = Physics2D.Linecast(targertPos , targertPos + new Vector2(x, y));
enemyCl.enabled = true;
if (hit.transform == null || hit.collider.tag == "Soda" || hit.collider.tag == "Food")
targertPos += new Vector2(x, y);


private void GetDown()
{//(检测点,检测范围,检测层级)
    if (!Physics2D.OverlapCircle(headUp.position, 0.2f, ground))
    {
        if ((Input.GetButton("Down")||PlayerCT .instent .IsD ) && gtext.IsTouchingLayers(ground))
        {
            ani.SetBool("Leiing", true);
            bx.enabled = false;
        }
        else if (!Input.GetButton("Down") || !gtext.IsTouchingLayers(ground))
        {
            ani.SetBool("Leiing", false);
            bx.enabled = true;
        }
    }
}

Collider是否接触到某层级LayMask
gtext.IsTouchingLayers(ground)