I started out basic with:
if (Input.GetKey (KeyCode.A))
gameObject.GetComponent().material.color = Color.red
But this chooses a random material and changes that to red, so i cant specify which one relates to which
From reading around, I found an array can possibly do this (the material change part, I know the palette GUI is a separate task), but I have no idea how to construct the full this script (artist not coder)
As much as I know about C# at the moment, thus a bit lost as I get error CS0103: The name `theNewMaterial’ does not exist in the current context and not sure how to ref that properly
Then I would also be looking at how to do the swapping via the interface palette as a second objective
The approach is correct, but theNewMaterial is an undefined variable. You should initialize it as an exposed variable, as you did with mats.
public Material theNewMaterial;
Then, through the Inspector, drag and drop a Material from your project to the variable’s value.
EDIT:
You can have three exposed variables identifing materials:
public Material plastic;
public Material wood;
pubblic Material metal;
Then, when you have to assign them at the chair:
mats = GetComponent<Renderer>().materials;
//Here, you have to assign with the exact order!
mats[0] = plastic;
mats[1] = wood;
mats[2] = metal;
GetComponent<Renderer>().materials = mats;
Probably the best bet will be to raycast at the chair or create buttons that completely envelop the interchangeable parts. Then on a button press or a ray hit you would just set the current material to be the next one in the list, or if you are at the end of the list loop back around to the beginning again.
I can post something of an example of it is needed, but I take no responsibility for inefficient or unoptimized code.
You cannot change the materials one by one, you have to replace the entire material[] array:
public Renderer r;
public Material newMaterial;
void changeMat()
{
//this code creates a copy of the original material array, replaces the first element with the
//"newMaterial" then assigns the new amterial list to the renderer
Material[] newMats = new Material[r.materials.Length];
r.materials.CopyTo(test, 0);
newMats[0] = newMaterial;
r.materials = newMats;
}
//I use this code to replace my character’s materials when it dies, it should work