BOOL Physics.raycast (Vector3 origin, Vector3 direction, float distance, int layermask)
True if Ray casts intersect with any collider, otherwise false.
BOOL Physics.raycast (Ray Ray, Vector3 direction, raycasthit out hit, float
distance, int layermask)
A light that can collide with all the collider in the scene and return details of the collision ().
BOOL Physics.raycast (Ray Ray, float distance, int layermask)
True if Ray casts intersect with any collider, otherwise false.
BOOL Physics.raycast (Vector3 origin, Vector3 direction, raycasthit out Hit,float
distance, int layermask)
True if Ray casts intersect with any collider, otherwise false.
Note: If the light is cast from the inside of a spherical body to the outside, it is returned as false.
Parameter understanding:
Origin: The starting point of the ray in world coordinates
Direction: direction of the Ray
Distance: Length of the Ray
Hit: Use the Out keyword in C # to pass in an empty collision information class, then assign a value after the collision. Can get a collision object
Transform,rigidbody,point and other information.
Layermask: Only the collider within the Layermask layer is selected, and the other in-layer collider is ignored. Selective collisions
Raycasthit[] Raycastall (Ray Ray, float distance, int layermask)
Casts a ray and returns all collisions, that is, projecting the light and returning a raycasthit[] structure.
The following is a small example of a pickup made using a ray (drag the code directly onto the main camera)
Using unityengine;using system.collections;public class raytest : monobehaviour { // use this for initialization void Start () { } // update is called once per frame void Update ( { if) ( Input.getmousebutton (0)) { ray ray = camera.main.screenpointtoray (Input.mousePosition) ;//X-ray from camera to click coordinates RaycastHit Hitinfo; if (Physics.Raycast (ray,out hitinfo))    &Nbsp; { debug.drawline (ray.origin,hitinfo.point);//underline the ray, only in scene view can see gameobject gameObj = hitInfo.collider.gameObject; debug.log ("click object name is " + Gameobj.name); if (gameobj.tag == "boot")//When the Ray collision target is the boot type of the item , perform a pickup operation { debug.log ("pick up!"); } } } }}
Unity physics.raycast Ray projection