unity射线检测忽略层级

时间:2021-04-08 17:56:55   收藏:0   阅读:166

1 << 10 检测第10层
~(1 << 10) 检测除了第10之外的层。 
~(1 << 0) 检测所有的层。 
(1 << 10) | (1 << 8) 检测第10和第8的层。

RaycastHit hit;
Vector3 dir;  //目标向量
float dis;    //最大距离
bool res = Physics.Raycast(self.position, dir, out hit, dis,~(1<<10));    //检测除第10层之外的    

bool res2 = Physics.Raycast(self.position, dir, out hit, dis,~(1 << LayerMask.NameToLayer("Monster")));    //检测除怪物层之外的 

 

原文:https://www.cnblogs.com/yifengs/p/14633071.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!