I’m trying to cast a ray cast in a straight line and get all the objects hit by the ray however I can only get the hit location of the first object the ray hits. How do I get all the hit points created by the ray?
Example.
if (Physics.Raycast(transform.position, Vector3.right * 20.0f, out hit))
{
Debug.Log (hit.point);
}
Obviously this is only going to display one hit.point no matter how many objects it hits because it’s only been called once when it hits the first object. Is there a way I can loop it until the ray doesn’t hit anything and each time return the object hit if that makes sense?