I want to change material shader in game, like from tessellation shader to a simple diffuse shader, i use this material as my ground texture. Now, when i try to play my game in unity editor, shader changes correctly, but when i build a separate pc game, my texture change from tessellated to plain pink color. Piece of code : Code (JavaScript): /*In some function*/ if(Input.GetKeyDown(KeyCode.V)) { if(tessellation) { ChangeTextures("Bumped Diffuse"); tessellation = false; } else { ChangeTextures("Tessellation/Bumped Specular (displacement)"); tessellation = true; } } function ChangeTextures(name : String) { var obj : GameObject[] = FindObjectsOfType(GameObject) as GameObject[]; for(var a : GameObject in obj) { if(a.name == "Earth Plain") { a.GetComponent(MeshRenderer).material.shader = Shader.Find(name); } } } So, what is wrong, whats happening in my game ? Is it not able to change a shader properly, or maybe material textures gets reseted and i need to set textures again after changing shader ?
Never mind, managed to do it by creating global array of Material, then creating some materials, assigning materials to array through unity Inspector, and then just changing in code a.getblaah.material = matsArray .