Laying Traps and Snapping to surface

I would like to know is there a way I can snap an object to another at runtime.

For Instance I have a room and I have 3 trap types
Roof Trap
Wall Trap
Floor Trap

I want my character to be able to lay a trap at runtime. So the process is

  1. Player Select a Floor Trap
  2. Looks at spot on floor where he wants to place the trap
    3)User presses button and an instance of the object is layd flatly on the floor.

Basically I want to snap the back of the Z axis of my trap to an object, like a floor wall or roof.

Yes I know its pretty much like the Game “Orcs must die” but I have another idea for it.

You could make a raycast when user press button. The RaycastHit returned contain information about the location the hit occurred and the normal the face have. You could then just do:

trap.transform.position = hit.position;
trap.transform.forward = hit.normal;