Casts a ray through the scene and returns all hits. Note that order is not guaranteed.
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; } } }
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]; Renderer 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 public class Example(MonoBehaviour): def Update() as void: 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 Renderer = hit.collider.renderer if renderer: renderer.material.shader = Shader.Find('Transparent/Diffuse') renderer.material.color.a = 0.3F i++