// Get the plane in Unity Plane plane = new Plane(Vector3.up, new Vector3(0, 0, 0)); // Cast a ray onto the plane Ray ray = new Ray(transform.position, Vector3.forward); float distance; if (plane.Raycast(ray, out distance)) { // Get the intersection point Vector3 intersectionPoint = ray.GetPoint(distance); // Draw a line from the object to the intersection point Debug.DrawLine(transform.position, intersectionPoint, Color.red); }
// Get the planes in Unity Plane[] planes = new Plane[3]; planes[0] = new Plane(Vector3.up, new Vector3(0, 0, 0)); planes[1] = new Plane(Vector3.up, new Vector3(0, 1, 0)); planes[2] = new Plane(Vector3.up, new Vector3(0, 2, 0)); // Cast rays onto each plane Ray ray = new Ray(transform.position, Vector3.forward); for (int i = 0; i < planes.Length; i++) { float distance; if (planes[i].Raycast(ray, out distance)) { // Get the intersection point Vector3 intersectionPoint = ray.GetPoint(distance); // Print out the intersection point Debug.Log("Intersection point with plane " + i + ": " + intersectionPoint); } }Package/Library: UnityEngine.