I had the same problem just now, so for others who were looking for a solution, here's mine:
first, I tried to see if the RayCast2D I created was responding to any layer (other than the players').
And it worked, the RayCast2D responded when I set its' collision to different layers.
Next, I checked my player's collision settings, and didn't find any problem there.
I decided to make a risky move, and deleded the player's Node from the main scene (for me it was level1) , and re-attached it to the same place.
AND IT WORKED!
I still don't know what was the initial problem, but at least I found a solution.
hope I could help someone :)