Aligning object to wall

In a room with lots of walls (as typical of a room), I want to do something similar to the sims where you can place windows/wallobjects on the walls and they stick to it. When the player wants to move the object to another wall it will rotate and then stick to that wall. My first idea was something like raycasting all four directions and then getting the wall position but I was wondering if there was a better way to do this.

My appropriately named sticktowall script. Not complete and probably going to cause me a lot of headaches.

RaycastHit hitback;
    RaycastHit hitforward;
    RaycastHit hitleft;
    RaycastHit hitright;
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
        
        Physics.Raycast(this.gameObject.transform.position, Vector3.back, out hitback);
        Physics.Raycast(this.gameObject.transform.position, Vector3.forward, out hitforward);
        Physics.Raycast(this.gameObject.transform.position, Vector3.left, out hitleft);
        Physics.Raycast(this.gameObject.transform.position, Vector3.right, out hitright);
        if (hitback.distance < hitforward.distance || hitback.distance < hitleft.distance || hitback.distance < hitright.distance)
        {
            this.gameObject.transform.position = hitback.transform.position;
            this.gameObject.transform.rotation = hitback.transform.rotation;
        }
        
        
	}

I used this in one of my games to place ‘splats’ on the sides of objects in the scene.

 public static void CreateSplat(Collision other, Vector3 position)
    {
        var splat = Instantiate<GameObject>(Resources.Load<GameObject>("Splat"));
        splat.gameObject.SetActive(true);
        splat.transform.position = position;
        var normal = other.contacts[0].normal;

        if (normal != Vector3.zero)
        {
            if ((int)normal.x != 0)
            {
                splat.transform.rotation = Quaternion.LookRotation(Vector3.forward, other.contacts[0].normal);
            }
            else
            {
                splat.transform.rotation = Quaternion.LookRotation(Vector3.left, other.contacts[0].normal);
            }

        }
        splat.transform.position += (normal * 0.25f); // This stops it from z-fighting with the object surface it lands on
    }