Legacy Documentation: Version 2017.2 (Go to current version)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

TerrainData.SetAlphamaps

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public method SetAlphamaps(x: int, y: int, map: float[,,]): void;
public void SetAlphamaps(int x, int y, float[,,] map);

Description

Assign all splat values in the given map area.

The array supplied to this function determines the width and height of the portion to be replaced. The third dimension of the array corresponds to the number of splatmap textures.

    // Blend the two terrain textures according to the steepness of
    // the slope at each point.
    function Start () {
        var map: float[,,] = new float[t.terrainData.alphamapWidth, t.terrainData.alphamapHeight, 2];

// For each point on the alphamap... for (var y = 0; y < t.terrainData.alphamapHeight; y++) { for (var x = 0; x < t.terrainData.alphamapWidth; x++) { // Get the normalized terrain coordinate that // corresponds to the the point. var normX = x * 1.0 / (t.terrainData.alphamapWidth - 1); var normY = y * 1.0 / (t.terrainData.alphamapHeight - 1);

// Get the steepness value at the normalized coordinate. var angle = t.terrainData.GetSteepness(normX, normY);

// Steepness is given as an angle, 0..90 degrees. Divide // by 90 to get an alpha blending value in the range 0..1. var frac = angle / 90.0; map[x, y, 0] = frac; map[x, y, 1] = 1 - frac; } }

t.terrainData.SetAlphamaps(0, 0, map); }

Did you find this page useful? Please give it a rating: