Ideally you’d raycast to the enemy’s position and check for collision with the wall object. However, you want to raycast into the screen, so raycasting to an object won’t work.
A possible solution is to put the enemies and walls into an Object Group, and raycast as before but against the object group. This will select the first object in the group that the ray collides with.
As subevents, you check the object type. If it’s a wall, destroy it (or do nothing). If it’s an enemy, inflict damage.
For example, the object group would be:
And the events:

