I've got a player firing out 2d raycasts. If one of them hits a boxcollider2d I would like to know if it hit the top side, bottom side, left side, or right side. How would I go about doing this? I've tried using Bounds but that didn't work out very well.
Compare contact point with bounds of your collider. You can get center and extents of collider to get coordinates of each side of collider, and see, which side contact point belongs to.
See image below for example.
Red line is raycast line, green square - collider. You can get contact point from RaycastHit2D. Then simply check: if contact point X coordinate is equal to bound
center.X + extents.X - it is either corner or right side. Same goes for left side - contact point X will be equal to
center.X - extents.X. For upper and lower check you just should change X to Y.
Also, don't forget, that it is possible for raycast to hit corner - X and Y of contact point in such situation will be equal to both
center.X +- extents.X and
center.Y +- extents.Y correspondingly.
For more details, see Bounds reference.