Skip to content

Instantly share code, notes, and snippets.

@estebanpadilla
Last active December 20, 2015 06:29
Show Gist options
  • Save estebanpadilla/6086105 to your computer and use it in GitHub Desktop.
Save estebanpadilla/6086105 to your computer and use it in GitHub Desktop.
Ray cast from object to detecting hit, draws a red line when a hit is detected otherwise draws a green light forward from object.
void Update () {
RaycastHit hit;
Vector3 fwd = transform.TransformDirection(Vector3.forward);
if (Physics.Raycast(transform.position, fwd, out hit, 10.0F)){
print("There is something in front of the object!");
Debug.DrawLine(transform.position, hit.collider.gameObject.transform.position, Color.red);
}
fwd = transform.TransformPoint(Vector3.forward * 4);
Debug.DrawLine(transform.position, fwd, Color.green);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment