in Unity 5, the best way that worked for me (TO MAKE OBJECT INVISIBLE) was to set all the materials of the game object that I would like to be invisible for transparency in rendering mode. Then click on the small round button next to the albedo, and then scroll through the list of items until you find one of them, called UIMask. Highlight it and press enter. I'm a newbie, so ask if you need more clarification.
* Please note that this is a hard fix, and I'm not sure if you can change this with code.
** This was done for borders in roll-a-ball with the player jump function enabled. it was necessary to make the walls invisible, but also collisions that could stop an object born in the air,
source share