我在Unity中创建了一个简单的Texture2D,如下所示(简化示例):
Texture2D texture2d = new Texture2D(256,256);
for (int h = 0; h < texture2d.height; h++) {
for (int w = 0; w < texture2d.width ; w++) {
texture2d.SetPixel(w,h, Color.green);
}
}
如何在现有地形上将此创建的Texture2D设置为地面纹理?
答案 0 :(得分:1)
由于内置'isadminB'
着色器没有Terrain
属性,因此您必须使用自定义属性:例如http://wiki.unity3d.com/index.php/TerrainFourLayerToon(放在_MainTexture
文件中)
从那里你只需要适当的代码
.shader
此代码应在Unity 5中运行
如果您对这些功能中的任何功能感到好奇,请检查//your code here
texture2d.Apply(); //missing in your code!
Material mat = new Material(Shader.Find("Terrain/Four Layer Toon Compat")); //from link
mat.SetTexture("_MainTex" , texture2d); //set the texture properties of the shader
mat.SetTexture("_MainTex2", texture2d);
mat.SetTexture("_MainTex3", texture2d);
mat.SetTexture("_MainTex4", texture2d);
Terrain terr = this.gameObject.GetComponent<Terrain>(); //get the terrain
terr.materialType = Terrain.MaterialType.Custom; //tell the terrain you want to manually assign its material
terr.materialTemplate = mat; //finally assign the material (and texture)
ShaderLab
,CG
和.shader
文件类型
UnityEngine
- &gt;下的和https://docs.unity3d.com/Manual/SL-Reference.html Classes
,GameObject
,Material
,Shader
和Terrain
的{{1}}。