Originally thought of this function how to realize, just in the project see here record.
First of all, there will be a basic material in the model of the project, which is the material of the model that the art gives you.
There may be a need to trigger an event in the game, add a streamer or stroke to your body.
We know that these effects should be shown in the body, with special effects is not good-looking, to use shader to express.
That's when you need to change a shader.
In fact, we will not directly change shader, is to change a material.
So it is essentially a new material that is basically copied from the original material, and changed his shader.
Then change the material at the time of the trigger.
Such as:
Material[] effectMaterials = new Material[materials.Length]; for (int j = effectMaterials.Length; --j >= 0;) { if (null == materials[j]) { effectMaterials[j] = null; continue; } Material effectMaterial = new Material(materials[j]); effectMaterial.shader = DistShader; effectMaterials[j] = effectMaterial; }
Unity Practical skills Unity replaces the shader of characters in the game, such as adding a streamer