版权声明:转载请注明出处!不注明也无所谓,嘿嘿。 https://blog.csdn.net/qq_15020543/article/details/82760188
射线检测相关整合在这https://blog.csdn.net/qq_15020543/article/details/82531658(里面有laymask和queryTriggerInteraction以及layer的介绍)
Physics.OverlapSphere 重叠球
C#
=> public static Collider[] OverlapSphere(Vector3 position, float radius, int layerMask = AllLayers, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);
Parameters 参数
position | Center of the sphere. 球体中心。 |
radius | Radius of the sphere. 球的半径。 |
layerMask | A Layer mask that is used to selectively ignore colliders when casting a ray. 在投射光线时,使用的层掩模可以选择性地忽略除他本身之外的碰撞器。 |
queryTriggerInteraction | Specifies whether this query should hit Triggers. 指定是否查询碰到触发器。 |
描述
返回球内或与之接触的所有碰撞器。注意,这个仅针对碰撞器的边界体检测,而不是针对实际的碰撞器。
这样一来collider就只会收集player层的碰撞体,大大节约了性能!
然后是计算伤害