Answers for "I don't understand Ray,RayCast,RaycastHit ??"http://answers.unity.com/questions/532509/i-dont-understand-rayraycastraycasthit-.html
The latest answers for the question "I don't understand Ray,RayCast,RaycastHit ??"Answer by aldonalettohttp://answers.unity.com/answers/532547/view.html
The ray is a geometric creature: a line starting at some point (the origin) and following indefinitely in some direction. Physics.Raycast is a test that verifies whether some collider is hit by the ray specified, and RaycastHit is a structure that Raycast fills with info about the first object hit by the ray - it has invalid values if nothing hit, thus only read it when Physics.Raycast returns true. A typical use for Raycast is to detect which object was clicked:
function Update(){
if (Input.GetMouseButtonDown(0)){ // if left mouse button pressed...
// get ray starting at camera position and passing through the mouse pointer:
var ray: Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit: RaycastHit; // allocate variable RaycastHit
if (Physics.Raycast(ray, hit)){ // if something hit...
print("Clicked on "+hit.transform.name); // print its name
} else {
print("Nothing hit");
}
}
}Sat, 07 Sep 2013 20:31:13 GMTaldonaletto