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);
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;
}
}
}
using UnityEngine;
using System.Collections;
public class example :
MonoBehaviour {
void Update() {
RaycastHit[] hits;
hits =
Physics.RaycastAll(transform.position, transform.forward, 100.0F);
int i = 0;
while (i < hits.Length) {
RaycastHit hit = hits[i];
System.
Object renderer = hit.collider.renderer;
if (renderer) {
renderer.material.shader =
Shader.Find(
"Transparent/Diffuse");
renderer.material.color.a = 0.3F;
}
i++;
}
}
}
import UnityEngine
import System.Collections
class example(
MonoBehaviour):
def
Update():
hits as (
RaycastHit)
hits =
Physics.RaycastAll(transform.position, transform.forward, 100.0F)
i as
int = 0
while i < hits.Length:
hit as
RaycastHit = hits[i]
renderer as System.
Object = hit.collider.renderer
if renderer:
renderer.material.shader =
Shader.Find('Transparent/Diffuse')
renderer.material.color.a = 0.3F
i++
Note: This function will return false if you cast a ray from
inside a sphere to the outside; this in an intended behaviour.