Rotate a part to match a surface?

Hello, Unity Answers. I’m trying to build a construction sandbox, and it needs an editor for assembling vehicles - currently I am working on part placement, and I am utterly stuck.
I need the part placer to rotate the part you’re placing so it’s back is to the part it’s being placed onto - so when I place it at an angle it doesn’t clip into it and instead places it so the part is diagonal.
I have no real idea where to look for that kind of thing, can anyone point me in the right direction on that?
Thanks in advance!

If the parts are set up in a way where the front faces the positive z axis (blue line), then there’s a pretty straightforward way to do it:

  1. Raycast from mouse to vehicle
  2. Set transform.forward on the copy of the part being placed to raycastHit.normal (and the position to raycastHit.point, naturally)
  3. Possibly fix transform.up if it’s wrong

If for some reason you wanted parts to face the positive x axis in their default position instead, you could use transform.right instead of transform.forward, and if you wanted them to face up then flip transform.forward and transform.up in 2. and 3.