public int Cast (Vector2 direction, RaycastHit2D[] results, float distance= Mathf.Infinity);

Parameters

direction表示每个 Collider2D 形状投射方向的矢量。
results用于接收结果的数组。
distanceMaximum distance over which to cast the Collider(s).

Returns

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

Description

All the Collider2D shapes attached to the Rigidbody2D are cast into the Scene starting at each Collider position ignoring the Colliders attached to the same Rigidbody2D.

This function will take all the Collider2D shapes attached to the Rigidbody2D and cast them into the Scene starting at the Collider position in the specified direction for an optional distance and return the results in the provided results array.

The integer return value is the number of results written into the results array. The results array will not be resized if it doesn't contain enough elements to report all the results. The significance of this is that no memory is allocated for the results and so garbage collection performance is improved when casts are performed frequently.

此外,这还将检测位于碰撞体开始位置的其他碰撞体(如果它们重叠)。在这种情况下,投射形状将从碰撞体内部开始,可能不与碰撞体表面交叠。这意味着无法计算碰撞法线,在这种情况下,返回的碰撞法线设置为正在测试的 direction 向量的倒数。


public int Cast (Vector2 direction, ContactFilter2D contactFilter, RaycastHit2D[] results, float distance= Mathf.Infinity);

Parameters

direction表示每个 Collider2D 形状投射方向的矢量。
contactFilter筛选由接触筛选器定义的结果。
results用于接收结果的数组。
distanceMaximum distance over which to cast the Collider(s).

Returns

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

Description

All the Collider2D shapes attached to the Rigidbody2D are cast into the Scene starting at each Collider position ignoring the Colliders attached to the same Rigidbody2D.

This function will take all the Collider2D shapes attached to the Rigidbody2D and cast them into the Scene starting at the Collider position in the specified direction for an optional distance and return the results in the provided results array.

The integer return value is the number of results written into the results array. The results array will not be resized if it doesn't contain enough elements to report all the results. The significance of this is that no memory is allocated for the results and so garbage collection performance is improved when casts are performed frequently.

The contactFilter parameter can filter the returned results by the options in ContactFilter2D.

此外,这还将检测位于碰撞体开始位置的其他碰撞体(如果它们重叠)。在这种情况下,投射形状将从碰撞体内部开始,可能不与碰撞体表面交叠。这意味着无法计算碰撞法线,在这种情况下,返回的碰撞法线设置为正在测试的 direction 向量的倒数。


Parameters

direction表示每个 Collider2D 形状投射方向的矢量。
resultsList to receive results.
distanceMaximum distance over which to cast the Collider(s).

Returns

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

Description

All the Collider2D shapes attached to the Rigidbody2D are cast into the Scene starting at each Collider position ignoring the Colliders attached to the same Rigidbody2D.

This function will take all the Collider2D shapes attached to the Rigidbody2D and cast them into the Scene starting at the Collider position in the specified direction for an optional distance and return the results in the provided results list.

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.

此外,这还将检测位于碰撞体开始位置的其他碰撞体(如果它们重叠)。在这种情况下,投射形状将从碰撞体内部开始,可能不与碰撞体表面交叠。这意味着无法计算碰撞法线,在这种情况下,返回的碰撞法线设置为正在测试的 direction 向量的倒数。


Parameters

direction表示每个 Collider2D 形状投射方向的矢量。
contactFilter筛选由接触筛选器定义的结果。
resultsList to receive results.
distanceMaximum distance over which to cast the Collider(s).

Returns

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

Description

All the Collider2D shapes attached to the Rigidbody2D are cast into the Scene starting at each Collider position ignoring the Colliders attached to the same Rigidbody2D.

This function will take all the Collider2D shapes attached to the Rigidbody2D and cast them into the Scene starting at the Collider position in the specified direction for an optional distance and return the results in the provided results list.

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 contactFilter parameter can filter the returned results by the options in ContactFilter2D.

此外,这还将检测位于碰撞体开始位置的其他碰撞体(如果它们重叠)。在这种情况下,投射形状将从碰撞体内部开始,可能不与碰撞体表面交叠。这意味着无法计算碰撞法线,在这种情况下,返回的碰撞法线设置为正在测试的 direction 向量的倒数。