unity3d 射线扫描 忽略图层

函数说明

static RaycastHit2D[] RaycastAll(Vector2 origin,Vector2 direction,float distance = Mathf.Infinity,int layerMask = DefaultRaycastLayers,float minDepth = -Mathf.Infinity,float maxDepth = Mathf.Infinity);
Parameters

originThe point in 2D space where the ray originates.
directionVector representing the direction of the ray.
distanceMaximum distance over which to cast the ray.
layerMaskFilter to detect Colliders only on certain layers.
minDepthOnly include objects with a Z coordinate (depth) greater than this value.
maxDepthOnly include objects with a Z coordinate (depth) less than this value.
Description

Casts a ray against colliders in the scene, returning all colliders that contact with it.发射一条射线到场景中,检测射线射到的所有碰撞机(collider)


//layermask的参数表示,要忽略的图层,在编辑器中的元素属性为Sprite Renderer->Order in Layer
//把要忽略的物体设置为对应图层,然后再raycastall函数中的layermask定义为该图层,射线就会忽略该图层
RaycastHit2D[] rhArFirst = Physics2D.RaycastAll(qieObject.transform.position, vectorDir, StageManager.elementSize,3);

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值