Unity's radiographic testing
Raycasthit hit; Storage of information after radiographic inspection
if ( physics.raycast (transform.position + vector3.up * 0.3f, Transform.forward, out hit, 5f))//radiographic inspection The return value is a bool value, the first parameter: the ray start position; The second parameter: the direction of the Ray (Transform.forward is the z-axis direction of the script object); the third parameter: storing the detection information in hit, of course and maxdistance: The maximum length of the ray; the fifth parameter: int layermask: A layer of ray detection.
{
if (hit.collider.tag = = "Obstacle" && speed >= 3&&anim. Getcurrentanimatorstateinfo (0). Isname ("Locamation"))some common methods of//raycasthit
{
Vector3 point = hit.point;
Point.y = hit.collider.transform.position.y + hit.collider.bounds.size.y;
Matchtarget = point;
}
}
}
Flexible application of radiographic testing
If (Input. Getmousebuttondown(0)) {
Raycasthit hit;Ray Ray .= Camera.Main.Screenpointtoray(Input.mouseposition);// Ray detection and camera mouse with the use of if (Physics. Raycast(Ray, out hits )) if (hit. Collider = null) hit. Collider. Enabled = false;
}
X-ray detection in Unity