Is there reason why this isn’t working? I’m not getting anything for the length1 variable. (I have declared a length1 variable elsewhere in the code[this is the only part that matters])
function Update() {
var fwd = transform.forward;
if(Physics.Raycast (transform.position, fwd, 50)){
length1 = Physics.RaycastHit.distance;
}
Debug.DrawRay(transform.position, transform.forward, Color.green, length1);
}
Ok thanks! Now I have another question, how can I get this to work?
function Update() {
var lineRenderer : LineRenderer = GetComponent(LineRenderer);
var fwd = transform.forward;
var hit: RaycastHit; // declare a RaycastHit variable...
// and pass it to the Raycast function:
if(Physics.Raycast(transform.position, fwd, hit, 50)){
length = hit.distance; // then get the result from the hit variable
}else
length = 100;
lineRenderer.positions[1].z = length;
}