如图所示,头顶画了四条射线,有关于人物挂墙的射线有三条
RaycastHit2D Raycast(Vector2 offset,Vector2 rayDiraction,float length,LayerMask layer)
{
Vector2 pos = transform.position;
RaycastHit2D hit = Physics2D.Raycast(pos + offset, rayDiraction, length, layer);
Color color = hit ? Color.red : Color.green;
Debug.DrawRay(pos + offset, rayDiraction * length,color,0.2f);
return hit;
}
这里为了画线方便,重载函数Raycast,形参解释
Vector2 offset画线起点(在人物锚点偏移的量)
Vector2 rayDiraction画线方向
float length画线的长度
LayerMask layer画出去的线和哪一层画布检测,这里我们就用自己要攀爬的画布
这个函数重载前两行将人物的现在移动到的坐标传给画线函数古,成为pos + offset,也就