unity3d中使用代码创建Material材质

时间:2025-05-12 10:47:24
  • Texture2D texture = null;//mat的texture
  •     public Material mat;//要创建的material
  •     void Start ()
  •     {
  •         //给texture添加一张png图片                              图片的路径                            图片的类型
  •         texture = ("Assets/Texture/", typeof(Texture2D))as Texture2D;
  •         //创建mat
  •         mat = new Material ( ("Standard"));
  •         //mat的texture
  •          = texture;
  •         //创建的mat材质放到Assets文件夹下
  •          (mat, "Assets/");
  •         //创建一个Cube
  •         GameObject objCube = ();
  •        //给cube的材质赋值
  •         <Renderer> ().material = mat;
  •     }
     
  • 相关文章