-5

I am getting this error: CS0161 C# '': not all code paths return a value. (I am using this videos if it can help you: https://www.youtube.com/watch?v=QN39W020LqU&list=PLFt_AvWsXl0cONs3T0By4puYy6GM22ko8 , https://www.youtube.com/watch?v=wbpMiKiSKm8&list=PLFt_AvWsXl0eBW2EiBtl_sxmDtSgZBxB3 , I am tring to use landmass color instead of gradient in planet) here is the code:

public Texture2D TextureFromHeightMap(float[,] heightMap)
{
    int width = heightMap.GetLength(0);
    int height = heightMap.GetLength(1);
    Texture2D texture = new Texture2D(width, height);

    Color[] colourMap = new Color[shapeSettings.planetRadius * shapeSettings.planetRadius];
    for (int y = 0; y < minMax.Max; y++)
    {
        for (int x = 0; x < shapeSettings.planetRadius; x++)
        {
            for (int i = 0; i < y; i++)
            {
                colourMap[y * width + x] = Color.Lerp(Color.black, Color.white, heightMap[x, y]);
            }
        }
        texture.SetPixels(colourMap);
        texture.Apply();
    }
}
filgas08
  • 51
  • 7

1 Answers1

1

You must return the texture.

public Texture2D TextureFromHeightMap(float[,] heightMap)
{
    int width = heightMap.GetLength(0);
    int height = heightMap.GetLength(1);
    Texture2D texture = new Texture2D(width, height);

    Color[] colourMap = new Color[shapeSettings.planetRadius * shapeSettings.planetRadius];
    for (int y = 0; y < minMax.Max; y++)
    {
        for (int x = 0; x < shapeSettings.planetRadius; x++)
        {
            for (int i = 0; i < y; i++)
            {
                colourMap[y * width + x] = Color.Lerp(Color.black, Color.white, heightMap[x, y]);
            }
        }
        texture.SetPixels(colourMap);
        texture.Apply();
    }
    return texture;
}
Lcj
  • 371
  • 3
  • 10