unityplayer中缺少TerrainTexture

时间:2018-07-08 00:53:03

标签: c# unity3d

当我在unityplayer中启动游戏时,地形的纹理消失了(图1)。当我在编辑器中启动同一场景时,它看起来应该是应该的(图2)。

我使用以下代码添加纹理:

terrainData.alphamapResolution = 500;
SplatPrototype[] terrainTexture = new SplatPrototype[2];
terrainTexture[0] = new SplatPrototype();
terrainTexture[0].texture = (Texture2D)Resources.Load("MyTexture/GrassHillAlbedo");
terrainTexture[1] = new SplatPrototype();
terrainTexture[1].texture = (Texture2D)Resources.Load("MyTexture/SandAlbedo");
terrainData.splatPrototypes = terrainTexture;

float[,,] splatMapData = new float[terrainData.alphamapWidth, terrainData.alphamapHeight, 2];

for (int x = 0; x < terrainData.alphamapWidth; x++)
{
    for (int y = 0; y < terrainData.alphamapHeight; y++)
    {
        // Grasland
        if (biomes[x, y] == 0)
        {
            splatMapData[x, y, 0] = 1;
            splatMapData[x, y, 1] = 0;
        }

        // Desert
        if (biomes[x, y] == 1)
        {
            splatMapData[x, y, 0] = 0;
            splatMapData[x, y, 1] = 1;
        }
    }
}

terrainData.SetAlphamaps(0, 0, splatMapData);

有人遇到这个问题或有解决方案吗?

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

好的,我找到了解决方案->纹理未启用“写入/读取”。