I have my material switching, however, when it switches, the shader automatically switches back from the prefab setting of Transparency/Diffuse to regular Diffuse, I have soured the forums for a solution but not sure where else to look…
GameObject g;
public Material t0,t1,t2,t3,t4,t5;
void Start () {
g = this.gameObject;
int i =Random.Range(0,6);
switch(i)
{
case 0:
g.renderer.material=t0;
break;
case 1:
g.renderer.material=t1;
break;
case 2:
g.renderer.material=t2;
break;
case 3:
g.renderer.material=t3;
break;
case 4:
g.renderer.material=t4;
break;
case 5:
g.renderer.material=t5;
break;
}
}
I don’t want the shader to change when I just change the material.
Never mind, figured it out…
public Material t0,t1,t2,t3,t4,t5;
void Start () {
g = this.gameObject;
int i =Random.Range(0,6);
switch(i)
{
case 0:
g.renderer.sharedMaterials[0]=t0;
break;
case 1:
g.renderer.sharedMaterials[0]=t1;
break;
case 2:
g.renderer.sharedMaterials[0]=t2;
break;
case 3:
g.renderer.sharedMaterials[0]=t3;
break;
case 4:
g.renderer.sharedMaterials[0]=t4;
break;
case 5:
g.renderer.sharedMaterials[0]=t5;
break;
}
}
Don’t you love it when you post a question and then right after you figure it out?
Ok well it still is a problem, I thought that fixed it but now it is ignoring my new material and using the default material…
SIGH
Such a headache for such a simple thing…
Ok, I have tried every angle at this point so it has to be some sort of bug, You can’t change the material without loosing the shader that was assigned, I just want all materials to use the Transparency/Diffuse shader, but there really doesn’t appear to be a way to do it in code but instead I have to make a prefab for every object which is ridiculous. Does anyone have any suggestions other than me having to do prefabs instead of just swapping materials?