Question by
GameMaker102 · Sep 19, 2017 at 10:15 PM ·
scripting problemerrorfunctionreturn
How to return a function
So I have this script:
public class TerrainTextures {
public void AssignTextures(Terrain terrain) {
TerrainData terrainData = terrain.terrainData;
float[,,] splatmapData = new float[terrainData.alphamapWidth, terrainData.alphamapHeight, terrainData.alphamapLayers];
for (int y = 0; y < terrainData.alphamapHeight; y++) {
for (int x = 0; x < terrainData.alphamapWidth; x++) {
float y1 = (float)y / (float)terrainData.alphamapHeight;
float x1 = (float)y / (float)terrainData.alphamapHeight;
float height = terrainData.GetHeight (Mathf.RoundToInt (y1 * terrainData.heightmapHeight), Mathf.RoundToInt (x1 * terrainData.heightmapWidth));
Vector3 normal = terrainData.GetInterpolatedNormal (y1, x1);
float steepness = terrainData.GetSteepness (y1, x1);
float[] splatWeights = new float[terrainData.alphamapLayers];
splatWeights [0] = Mathf.Clamp01 (terrainData.heightmapHeight - height);
splatWeights [1] = Mathf.Clamp01 ((terrainData.heightmapHeight + height));
splatWeights [2] = 1.0f - Mathf.Clamp01 (steepness * steepness / (terrainData.heightmapHeight / 5.0f));
splatWeights [3] = height * Mathf.Clamp01 (normal.z);
float z = splatWeights.Sum();
for (int i = 0; i < terrainData.alphamapLayers; i++) {
splatWeights [i] /= z;
splatmapData [x, y, i] = splatWeights [i];
}
}
}
return terrain.terrainData.SetAlphamaps (0, 0, splatmapData);
}
}
It's perfectly fine, except when I try to return terrain.terraindata.SetAlphaMaps (0, 0, splatmapData); I get this error: "Assets/World/Procedural/Textures/Scripts/TerrainTextures.cs(41,25): error CS0127: `ProceduralTerrain.TerrainTextures.AssignTextures(UnityEngine.Terrain)': A return keyword must not be followed by any expression when method returns void" So I know I can't use void, but I don't know what to use instead. If that's not right, then can I even return a function?
Comment
You can't return a void. Simply delete the return keyword.