Version: 2017.1

Physics2D.RaycastNonAlloc

Cambiar al Manual
public static int RaycastNonAlloc (Vector2 origin, Vector2 direction, RaycastHit2D[] results, float distance= Mathf.Infinity, int layerMask= DefaultRaycastLayers, float minDepth= -Mathf.Infinity, float maxDepth= Mathf.Infinity);

Parámetros

minDepth Only include objects with a Z coordinate (depth) greater than or equal to this value.
maxDepth Only include objects with a Z coordinate (depth) less than or equal to this value.
origin The point in 2D space where the ray originates.
direction The vector representing the direction of the ray.
results Arreglo para recibir resultados.
distance Distancia máxima sobre el cual se emite el rayo.
layerMask Filtro para revisar objetos solamente en capas especificas.

Valor de retorno

int Returns the number of results placed in the results array.

Descripción

Casts a ray into the scene.

This function is similar to the RaycastAll function except that the results are returned in the supplied array. The integer return value is the number of objects that intersect the line (possibly zero) but 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 raycasts are performed frequently.

Additionally, this will also detect Collider(s) at the start of the ray. In this case the ray is starting inside the Collider and doesn't intersect the Collider surface. This means that the collision normal cannot be calculated in which case the collision normal returned is set to the inverse of the ray vector being tested. This can easily be detected because such results are always at a RaycastHit2D fraction of zero.

See Also: LayerMask class, RaycastHit2D class, Raycast, Linecast, DefaultRaycastLayers, IgnoreRaycastLayer, raycastsHitTriggers.