Physics.RaycastAll Manual     Reference     Scripting  
Scripting > Runtime Classes > Physics
Physics.RaycastAll

static function RaycastAll (ray : Ray, distance : float = Mathf.Infinity, layerMask : int = kDefaultRaycastLayers) : RaycastHit[]

static function RaycastAll (origin : Vector3, direction : Vector3, distance : float = Mathf.Infinity, layermask : int = kDefaultRaycastLayers) : RaycastHit[]

Description

Casts a ray through the scene and returns all hits.

function Update () {
var hits : RaycastHit[];
hits = Physics.RaycastAll (transform.position, transform.forward, 100.0);

// Change the material of all hit colliders
// to use a transparent Shader
for (var i=0;i<hits.length;i++)
{
var hit : RaycastHit = hits[i];
var renderer = hit.collider.renderer;
if (renderer)
{
renderer.material.shader = Shader.Find("Transparent/Diffuse");
renderer.material.color.a = 0.3;
}
}
}