Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将纹理指定给统一的材质_C#_Unity3d - Fatal编程技术网

C# 如何将纹理指定给统一的材质

C# 如何将纹理指定给统一的材质,c#,unity3d,C#,Unity3d,我看了文件,这应该行得通 MeshRenderer mesh_renderer = gameObject.GetComponent<MeshRenderer> (); mesh_renderer.material = Resources.Load<Material> ("MapMaterial"); mesh_renderer.material.mainTexture = Resources.Load<Texture> ("cobblestone"); me

我看了文件,这应该行得通

MeshRenderer mesh_renderer = gameObject.GetComponent<MeshRenderer> ();
mesh_renderer.material = Resources.Load<Material> ("MapMaterial");
mesh_renderer.material.mainTexture = Resources.Load<Texture> ("cobblestone");
mesh渲染器mesh\u renderer=gameObject.GetComponent();
mesh_renderer.material=Resources.Load(“MapMaterial”);
mesh_renderer.material.mainTexture=Resources.Load(“鹅卵石”);
但它会指定一个空的默认材质


cobblestone.jpg位于assets文件夹中,因此它应该可以正常工作?

否它将根据assets\Resources文件夹搜索您请求的资源

// This will search for 'cobblestone' in Assets/Resources/cobblestone.jpg:
mesh_renderer.material.mainTexture = Resources.Load("cobblestone", typeof(Texture2D));