How to make c# script affect only the object it is assigned to?

I have a house scene with furniture objects in it. Far below, is the same house with the objects messy version. This script is on every clean object.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Cleaning : MonoBehaviour {

	private bool initialCleaned;
	private bool cleaned;
	public GameObject clean;
	public GameObject messy;

	void Update () {
		if (!initialCleaned) {
			Vector3 tempPosition = clean.transform.position;
			clean.transform.position = messy.transform.position;
			messy.transform.position = tempPosition;
			initialCleaned = true;	
		}
		if (!cleaned){
			if (Input.GetMouseButtonDown (0)) {
				Ray toMouse = Camera.main.ScreenPointToRay (Input.mousePosition);
				RaycastHit rhInfo;
				bool didHit = Physics.Raycast (toMouse, out rhInfo, 2.0f);
				if (didHit) {
					Vector3 tempPosition = clean.transform.position;
					clean.transform.position = messy.transform.position;
					messy.transform.position = tempPosition;
					cleaned = true;	
					}
				}
			}
		}
	}

The script basically checks if the object is cleaned or not, then swaps the place of the two models if it isn’t, or, back again when it is. This is all for lighting reasons, so it must be this way. The problem is that when one object, say, the bed, is cleaned, it sets the bool true for all objects in the house, and everything else reverts to its clean state.
How do I make it so the script only affects the object it is attached to?

How to make c# script affect only the object it is assigned to?

That’s exactly what they are doing with the code you have, but that’s not the problem you have. Your problem is that all the instances of your script do this no matter which one of them is hit by the ray.

Right now the condition for doing the swap is didHit. So all your objects do a raycast and if it hits something, all the scripts do the swap.

You should do the swap only on the object that gets hit by the ray. For example

if (didHit && rhInfo.collider.gameObject == this.gameObject) {