public static RaycastHit2D CapsuleCast (Vector2 origin, Vector2 size, CapsuleDirection2D capsuleDirection, float angle, Vector2 direction, float distance= Mathf.Infinity, int layerMask= DefaultRaycastLayers, float minDepth= -Mathf.Infinity, float maxDepth= Mathf.Infinity);

Parameters

origin胶囊体在 2D 空间中的起点。
size胶囊体的大小。
capsuleDirection胶囊体的方向。
angle胶囊体的角度(以度为单位)。
direction表示胶囊体投射方向的向量。
distanceThe maximum distance over which to cast the capsule.
layerMask过滤器,用于仅在特定层上检测碰撞体。
minDepth仅包括 Z 坐标(深度)大于该值的对象。
maxDepth仅包括 Z 坐标(深度)小于该值的对象。

Returns

RaycastHit2D 返回的投射数量。

Description

Casts a capsule against colliders in the Scene, returning the first collider to contact with it.

A CapsuleCast is conceptually like dragging a capsule through the Scene in a particular direction. Any object making contact with the capsule can be detected and reported.

函数返回一个 RaycastHit2D 对象,该对象引用了胶囊体命中的碰撞体(如果未命中任何对象,则结果的碰撞体属性将为 NULL)。layerMask 可用于仅在特定层上有选择地检测对象(例如,这让您能够仅将检测应用于敌人角色)。

返回的 RaycastHit2D 将返回胶囊体将与碰撞体接触的点和法线。此外,它还返回当胶囊体接触该点时胶囊体的质心。

另请参阅:LayerMask 类、RaycastHit2D 类、CapsuleCastAllCapsuleCastNonAllocDefaultRaycastLayersIgnoreRaycastLayerraycastsHitTriggers


public static int CapsuleCast (Vector2 origin, Vector2 size, CapsuleDirection2D capsuleDirection, float angle, Vector2 direction, ContactFilter2D contactFilter, RaycastHit2D[] results, float distance= Mathf.Infinity);

Parameters

origin胶囊体在 2D 空间中的起点。
size胶囊体的大小。
capsuleDirection胶囊体的方向。
angle胶囊体的角度(以度为单位)。
direction表示胶囊体投射方向的向量。
contactFilter接触筛选器,用于以不同方式筛选结果,例如按层遮罩、Z 深度或法线角度。
results用于接收结果的数组。该数组的大小决定可返回的结果的最大数量。
distanceThe maximum distance over which to cast the capsule.

Returns

int 返回放置在 results 数组中的结果数。

Description

向场景中的碰撞体投射胶囊体,并返回与胶囊体接触的所有碰撞体。

A CapsuleCast is conceptually like dragging a capsule through the Scene in a particular direction. Any object making contact with the capsule can be detected and reported.

该函数返回找到的接触点数,并将这些接触点放入 results 数组。也可以通过 contactFilter 对结果进行过滤。

另请参阅:ContactFilter2DRaycastHit2D


Parameters

origin胶囊体在 2D 空间中的起点。
size胶囊体的大小。
capsuleDirection胶囊体的方向。
angle胶囊体的角度(以度为单位)。
directionA vector representing the direction to cast the capsule.
contactFilter接触筛选器,用于以不同方式筛选结果,例如按层遮罩、Z 深度或法线角度。
resultsThe list to receive results.
distanceThe maximum distance over which to cast the capsule.

Returns

void Returns the number of results placed in the results list.

Description

Casts a capsule against the Colliders in the Scene and returns all Colliders that are in contact with it.

A CapsuleCast is conceptually like dragging a capsule through the Scene in a particular direction. Any Collider making contact with the capsule can be detected and reported.

The integer return value is the number of results written into the results list. The results list will be resized if it doesn't contain enough elements to report all the results. This prevents memory from being allocated for results when the results list does not need to be resized, and improves garbage collection performance when the query is performed frequently.

The results can also be filtered by the contactFilter.

另请参阅:ContactFilter2DRaycastHit2D