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(,));
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.

上一篇:ios的虚拟键盘与fixed移动端的bug


下一篇:在 Android 的文字编辑控件 (TEdit) 中, 如何按下 Enter 就隐藏虚拟键盘