Creating Materials at runtime And Issue of Shader.Find()

Creating Materials at runtime
http://forum.unity3d.com/threads/create-materials-at-runtime.72952/

//通过Shader.Find()创建材质
floor.renderer.material = new Material (Shader.Find(" Diffuse"));
//设置材质参数
floor.renderer.material.SetTextureScale("Tiling", new Vector2(100,0));
floor.renderer.material.mainTexture = Resources.Load("Floor") as Texture2D;

 

Shader.Find()
http://docs.unity3d.com/ScriptReference/Shader.Find.html

 

Shader.Find()

需要注意的问题是,如果Shader是自己写的,则必须放置在Resources下面,否则在Android/iOS环境下,则会出现找不到Shader的问题。

When building a player, a shader will only be included if it is assigned to a material that is used in any scene or if the shader is placed in a "Resources" folder.

We should put the custom shaders into the 'Resources/Shaders/' folder, otherwise, when we built an android apk, shit happens.

posted @ 2016-04-07 11:48  elfnaga  阅读(234)  评论(0编辑  收藏  举报