赞
踩
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,放入工程中:
- Shader "UI/Default Grey" {
- Properties {
- _MainTex ("Base (RGB)", 2D) = "white" {}
- _Specular ("Specular", Range(1.0, 500.0)) = 250.0
- }
- ...
2、创建一个材质
- Material mat = new Material(Shader.Find("UI/Default Grey"));
- (img.GetComponent<Renderer>() as Renderer).material = mat;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。