- Home /
Question by
AR_Rizvi · Sep 02, 2013 at 07:26 AM ·
terraindataterraintexturesplatmaps
Spalt Maps Problem....
hi guys i am trying to set textures on terrian by spalt maps but it dsnt work i am using the simple code to set the texures but it returning null value every time i test it with diffrent ways can u guys help me in solving this problem here is the code i am using plz help... thanks
SplatPrototype[] terrainTexture = new SplatPrototype[4];
terrainTexture[0] = new SplatPrototype();
terrainTexture[0].texture = (Texture2D)Resources.Load("TEX/GLO_TIL_BRICK_439_MAP_L9_2013_1");
terrainTexture[0].tileOffset = new Vector2(0, 0);
terrainTexture[0].tileSize = new Vector2(15, 15);
Debug.Log ( terrainTexture[0]);
Debug.Log ( tex1);
terrainTexture[1] = new SplatPrototype();
terrainTexture[1].texture =(Texture2D)Resources.Load("TEX/GLO_TIL_BRICK_656_MAP_L9_2013_1");
terrainTexture[1].tileOffset = new Vector2(0, 0);
terrainTexture[1].tileSize = new Vector2(15, 15);
terrainTexture[2] = new SplatPrototype();
terrainTexture[2].texture =(Texture2D)Resources.Load("TEX/GLO_TIL_FINERY_180_MAP_L9_2013_1");
terrainTexture[2].tileOffset = new Vector2(0, 0);
terrainTexture[2].tileSize = new Vector2(15, 15);
terrainTexture[3] = new SplatPrototype();
terrainTexture[3].texture =(Texture2D)Resources.Load("TEX/GLO_TIL_GRASS_002_MAP_L9_2013_1");
terrainTexture[3].tileOffset = new Vector2(0, 0);
terrainTexture[3].tileSize = new Vector2(15, 15);
terrainData.splatPrototypes = terrainTexture;
float[,,] map = new float[terrainData.heightmapWidth-1,terrainData.heightmapHeight-1, 4]; // needs to be 1
// For each point on the alphamap...
for (int y = 0; y < terrainData.heightmapWidth-1; y++)
{
for (int x = 0; x < terrainData.heightmapHeight-1; x++)
{
if(terrainData.GetHeight(y,x)<10)
map[x, y, 0] = 1.0f;
else if(terrainData.GetHeight(y,x)<20)
{
map[x, y, 0] = 0.5f;
map[x, y, 1] = 0.5f;
}
else if(terrainData.GetHeight(y,x)<30)
map[x, y, 1] = 1.0f;
else if(terrainData.GetHeight(y,x)<40)
{
map[x, y, 1] = 0.5f;
map[x, y, 2] = 0.5f;
}
else if(terrainData.GetHeight(y,x)<50)
map[x, y, 2] = 1.0f;
else if(terrainData.GetHeight(y,x)<60)
{
map[x, y, 2] = 0.5f;
map[x, y, 3] = 0.5f;
// print (terrainData.GetHeight(y,x));
}
else if(terrainData.GetHeight(y,x)<70)
map[x, y, 3] = 1.0f;
else if(terrainData.GetHeight(y,x)<80)
{
map[x, y, 3] = 0.5f;
map[x, y, 4] = 0.5f;
// print (terrainData.GetHeight(y,x));
}
else if(terrainData.GetHeight(y,x)<90)
map[x, y, 4] = 1.0f;
}
}
terrainData.SetAlphamaps(0, 0, map);
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613113420im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
offset and misbehaviour Issue with the 'Paint Texture' tool in the Terrain Editor 0 Answers
Can we use a terrain-style splat shader on custom ground geometry? 1 Answer
Edit terrain by script?? 0 Answers
Getting the texture of a certain point on terrain 1 Answer
Terrain Texture (applied programatically) Disappears When Entering Play Mode 0 Answers