- Home /
Is this the correct way?
Hi, is this he correct way to change a shader and texture of a model from one to another in runtime, or is there a more efficient way of doing it?
 var shader1 : Shader;
 var shader2 : Shader;
 var material1 : Material;
 var material2 : Material;
 var material3 : Material;
 var testbot : GameObject;
 var testGun : GameObject;
 
 function Start () {
 
     shader1 = Shader.Find("Mobile/VertexLit");
     shader2 = Shader.Find("Mobile/Diffuse");
 }
 
 function Update () {
 
     if (Input.GetButtonDown("Jump")) {
         if( testbot.renderer.material.shader == shader1 ){
             testbot.renderer.material.shader = shader2;
             testbot.renderer.material = material2;
 
             testGun.renderer.material.shader = shader2;
             testGun.renderer.material = material2;
         }else{
             testbot.renderer.material.shader = shader1;
             testbot.renderer.material = material1;
 
             testGun.renderer.material.shader = shader1;
             testGun.renderer.material = material3;
         }
     }
 }
Answer by kubci98 · Jun 22, 2013 at 04:13 PM
It is the easiest way and i think that also the best. Next time, think about better title.
Answer by keeperkai2 · Jun 26, 2013 at 03:22 PM
If you only want to change the appearances of a few objects in the scene, it's the correct way, but if you want to render the whole scene with a different set of shaders, you should use replacement shaders:here.
Your answer
 
 
             Follow this Question
Related Questions
Can't find unlit shader in material shader selection!, 1 Answer
How can i make a shader to get this effect? 0 Answers
Shader: get back scene pixel color? 1 Answer
How can I edit Material Textures without creating a new Shader?,How to edit Material Texture 1 Answer
Material is not visible in android build but works fine in editor? 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                