Damage script issue

Hi, I wasn’t quite sure what to call the question so I will explain more here.

I am creating an RTS game from which I have a Buildings.cs which contains this:

// CUSTOM DAMAGE MESH
	public Mesh medium;
	public Mesh heavy;

void Update () 
	{
		if (health <= 0) {
			DestroyUnit ();
		} else if (health < 33) {
			GetComponent<MeshFilter>().mesh = Resources.Load<Mesh>("models/GRI/Buildings/ConYard/conYard-heavy");
			GetComponent<Renderer>().material = Resources.Load<Material>("models/GRI/Buildings/ConYard/conYard-heavy/Materials");
		} else if (health < 66) {
			GetComponent<MeshFilter>().mesh = Resources.Load<Mesh>("models/GRI/Buildings/conYard-low");
			GetComponent<Renderer>().material = Resources.Load<Material>("models/GRI/Buildings/ConYard/conYard-low/Materials");
		}
		

	}

So I have used this to load a different mesh when the health returns a certain value which I will ad works great. My problem is that this is now added to every building meaning the main mesh changes to the specific mesh when health reduces.

Is there any way to create a custom script for individual buildings that use this class that can be placed on the separate buildings? What I mean by that is the mesh and material call is for the
construction yard therefore I want an extra script that contains the class to change the mesh for the con yard but where it shares the function from the building.cs, this way I can create copies of the script but rename them for the buildings and change the resource location for: Barracks, War Factory, Airfield and so on.

You only need to change the value of the parameter of the load function for a public variable that gets changed depending on the building.

 // CUSTOM DAMAGE MESH
     public Mesh medium;
     public Mesh heavy;
   public Material mediumMaterial;
   public Material heavyMaterial;

   public string mediumPath = "";
   public string heavyPath = "";
   public string mediumMaterialPath = "";
   public string heavyMaterialPath = "";

void Start() {
   medium = Resources.Load(mediumPath);
   heavy = Resources.Load(heavyPath);
   mediumMaterial = Resources.Load(mediumMaterialPath);
   heavyMaterial = Resources.Load(heavyMaterialPath);
}

 void Update () 
     {
         if (health <= 0) {
             DestroyUnit ();
         } else if (health < 33 && GetComponent<MeshFilter>().mesh != heavy) {
             GetComponent<MeshFilter>().mesh = heavy;
             GetComponent<Renderer>().material = heavyMaterial;
         } else if (health < 66 && GetComponent<MeshFilter>().mesh != medium) {
             GetComponent<MeshFilter>().mesh = medium;
             GetComponent<Renderer>().material = mediumMaterial;
         }
     }

This way you can use the same script in all the buildings and you only need to change the paths to make each building load different meshes/materials. You can change the path from the script you use to spawn the building (or the editor or whatever). In this case it’s the conyard, but you can set any path you need.

[Edit] Of course, you need to make sure string paths are not empty before loading, and check if what you tried to load gets loaded and all that stuff.