I’d like to check for a box at the end of a raycast (hit point).
The problem is that the only function that I know of that can do this is Physics.CheckBox, but that returns a bool, and i want the object that has collided with this box.
Anyone know how to do this?
You can get the raycast hit position and cast a box there, like this:
#region Raycast Variables
Ray raycast = new Ray(startPosition, direction);
RaycastHit raycastHit;
float raycastLength = 10;
#endregion
// You can access the gameobject of a collider easily
Collider[] gameobjects;
if (Physics.Raycast(raycast, out raycastHit, raycastLength, layerMask))
gameobjects =
Physics.OverlapBox(raycastHit.point, boxHalfExtents, boxRotation, layerMask);