I am trying cast a ray that once it hits a gameobject within less than 100 range it will return the gameobject…
This is what I got:
var hit : RaycastHit;
function FixedUpdate () {
if (Physics.Raycast (transform.position, Vector3(-1, 0, -1), 100)) {
print ("There is something in front of the object! y-");
Debug.Log(hit.collider.gameObject.name);
}
}
// Raycast up to 100 meters down
function Update () {
var hit : RaycastHit;
if (Physics.Raycast (transform.position, -Vector3.up, hit, 100.0)) {
var distanceToGround = hit.distance;
}
}
The variable ‘hit’ contains a reference to the collider.
Thank you!
– Daniel_G