This is essentially correct… Shader.Find finds a named Shader has nothing (not much) to do with materials.
Using the references to the materials themselves would allow you to make cubes (any gameobject but cubes are simple to grasp) wood,brick or metal. Changing the shader on a game object’s material would make a solid wood cube a transparent wood cube (for instance).
Either way you end up with an array of materials or specific hard coded variables to hold the references to your base materials (wood,metal,brick).
Assuming you want to turn cubes into wood,brick or metal you could then do.
public var woodMat:Material;
public var brickMat:Material;
public var metalMat:Material;
function ChangeObjectAppearance(objectToChange : GameObject , newmaterial:string)
{
if(newmaterial=="wood")
{
objectToChange .renderer.material=woodMat;//game object is now wood
}
if(newmaterial=="brick")
{
objectToChange .renderer.material=brickMat;//game object is now brick
}
if(newmaterial=="metal")
{
objectToChange .renderer.material=metalMat;//game object is now metal
}
}
and in your interactive code you would call ChangeObjectAppearance(cubeobject,“wood”);
OR using an array
public var mySourceMaterials : Material[];
function ChangeObjectAppearance(objectToChange : GameObject , newmaterial:int)
{
gameObject.renderer.material=mySourceMaterials [newmaterial]; //game object is which ever material you linked and specified
}
and in your interactive code you would call ChangeObjectAppearance(cubeobject,0); assuming wood was the first material you dragged into the array in the inspector.
Either way you would manually drag the 3 materials in the inspector onto the relevant coded material.
In the hard coded case you would drag the wood material onto the entry called woodMat, brick onto the brickMat and metal onto the metalMat.
In the array case you would manually drag the 3 materials in the inspector onto the mySourceMaterials entry in the inspector. Each time you drop a a material a new entry will be added.
Swapping out the shader directly would be more of using the shader to indicate that the player is hovering over it by turning it transparent or glowy or what ever.
In this case your materials wouldn’t be wood,brick metal they would be ViewNormal and VewTransparent. So when you moved the mouse you would call a modified version of the array based ChangeObjectAppearance function that looked similar to this
gameObject.renderer.material.shader=mySourceMaterials[newmaterial].shader;
where the mySourceMaterials array held references to your ViewNormal and ViewTransparent materials.