如何解决CS0161 C#'':并非所有代码路径都返回值
我收到此错误: CS0161 C#'':并非所有代码路径都返回值。 (如果可以帮助您,我正在使用以下视频:https://www.youtube.com/watch?v=QN39W020LqU&list=PLFt_AvWsXl0cONs3T0By4puYy6GM22ko8,https://www.youtube.com/watch?v=wbpMiKiSKm8&list=PLFt_AvWsXl0eBW2EiBtl_sxmDtSgZBxB3,我正在尝试使用陆地颜色代替行星中的渐变色) 这是代码:
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();
}
}
解决方法
您必须返回纹理。
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;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。