Skip to content

Instantly share code, notes, and snippets.

@DomDomHaas
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DomDomHaas/e31156e8c67dbcad8637 to your computer and use it in GitHub Desktop.
Save DomDomHaas/e31156e8c67dbcad8637 to your computer and use it in GitHub Desktop.
Unity RayCast from clicking
Vector3 clickPos = new Vector3 (Input.mousePosition.x, Input.mousePosition.y, 0);
Ray camRay = Camera.main.ScreenPointToRay (clickPos);
RaycastHit hit;
if (Physics.Raycast (camRay.origin, camRay.direction,
out hit, rayLength, fieldMask)) {
// do awesome stuff here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment