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.