A Raycast checks whether an invisible ray hits something.
if (Physics.Raycast(
transform.position,
transform.forward,
out RaycastHit hit,
5f,
layerMask))
{
Debug.Log(hit.collider.name);
}
Useful hit data:
hit.point
hit.normal
hit.distance
hit.collider
hit.transform
Common uses: