Unity動態建立帶有Shader的Material
阿新 • • 發佈:2018-12-26
Unity5.x不在允許通過string的格式給材質新增shader,必須通過shaderAssets,否則警告:
UnityEngine.Material.Material(string) is obsolete:'Creating materials from shader source string is no longer supported. Use Shader assets instead.'
具體操作方法:
1、新增一個Shader,放入工程中:
2、建立一個材質Shader "UI/Default Grey" { Properties { _MainTex ("Base (RGB)", 2D) = "white" {} _Specular ("Specular", Range(1.0, 500.0)) = 250.0 } ...
Material mat = new Material(Shader.Find("UI/Default Grey"));
(img.GetComponent<Renderer>() as Renderer).material = mat;