当前位置:   article > 正文

Unity动态创建带有Shader的Material_material unity createwithstring

material unity createwithstring

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,放入工程中:

        

  1. Shader "UI/Default Grey" {
  2. Properties {
  3. _MainTex ("Base (RGB)", 2D) = "white" {}
  4. _Specular ("Specular", Range(1.0, 500.0)) = 250.0
  5. }
  6. ...
      2、创建一个材质

      

  1. Material mat = new Material(Shader.Find("UI/Default Grey"));
  2. (img.GetComponent<Renderer>() as Renderer).material = mat;

     

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/107668
推荐阅读
相关标签
  

闽ICP备14008679号