C# Unity ToBuiltIn()错误?简单的回答?
我所写的一切都是用Unity API编写的 因此,我有以下代码来帮助我生成地形:C# Unity ToBuiltIn()错误?简单的回答?,c#,unity3d,C#,Unity3d,我所写的一切都是用Unity API编写的 因此,我有以下代码来帮助我生成地形: Array CreateTerrainVertices(float[] _heightmap, float _resolution) { Debug.Log("Creating terrain vertices"); // The minimum resolution is 1 resolution = Mathf.Max(1, resolution); Array vertice
Array CreateTerrainVertices(float[] _heightmap, float _resolution)
{
Debug.Log("Creating terrain vertices");
// The minimum resolution is 1
resolution = Mathf.Max(1, resolution);
Array vertices = new Array();
// For each point, in the heightmap, create a vertex for
// the top and the bottom of the terrain.
for (int i = 0; i < _heightmap.Length; i++) {
vertices.Push(new Vector2(i / resolution, _heightmap[i]));
vertices.Push(new Vector2(i / resolution, 0));
}
Debug.Log("Created " + vertices.length + " terrain vertices");
return vertices.ToBuiltin(Vector2) as Vector2[];
}
我收到错误“Vector2是一个类型,在这个上下文中无效”。但当我移除向量2时,它看起来像:
return vertices.ToBuiltin() as Vector2[];
它告诉我我需要在参数中输入一个类型。。。但是看看我得到的第一个错误,上面写着“Vector2是一种类型…”
我怎样才能解决这个问题?什么属于那里?您正在创建一个大小灵活的数组对象,添加固定数量的元素,然后尝试将其转换为固定大小的数组 使用UnityEngine.Lang.Array.ToBuiltIn(Type)的正确方法是向其传递一个Type对象,指定对象应转换为的类型
return vertices.ToBuiltIn(typeof(Vector2)); // I am removing the "as Vector2[]" as it has no effect
但是,总体而言,这是一个低效的解决方案,因为阵列在组合期间需要多次调整大小,然后再进行转换。为什么不立即创建具有正确类型和大小的数组
Array CreateTerrainVertices(float[] _heightmap, float _resolution)
{
Debug.Log("Creating terrain vertices");
// The minimum resolution is 1
resolution = Mathf.Max(1, resolution);
Vector2[] vertices = new Vector2[_heightmap.Length * 2];
// For each point, in the heightmap, create a vertex for
// the top and the bottom of the terrain.
for (int i = 0; i < _heightmap.Length; i++)
{
vertices[i * 2] = new Vector2(i / resolution, _heightmap[i]);
vertices[i * 2 + 1] = new Vector2(i / resolution, 0);
}
Debug.Log("Created " + vertices.length + " terrain vertices");
return vertices;
}
Array CreateTerrainVertices(float[]\u高度映射,float\u分辨率)
{
Log(“创建地形顶点”);
//最小分辨率为1
分辨率=数学最大值(1,分辨率);
Vector2[]顶点=新Vector2[_heightmap.Length*2];
//在高度贴图中,为每个点创建顶点
//地形的顶部和底部。
对于(int i=0;i<\u heightmap.Length;i++)
{
顶点[i*2]=新向量2(i/分辨率,_高度映射[i]);
顶点[i*2+1]=新矢量2(i/分辨率,0);
}
Log(“已创建”+顶点.length+“地形顶点”);
返回顶点;
}
您正在创建一个大小灵活的数组对象,添加固定数量的元素,然后尝试将其转换为固定大小的数组
使用UnityEngine.Lang.Array.ToBuiltIn(Type)的正确方法是向其传递一个Type对象,指定对象应转换为的类型
return vertices.ToBuiltIn(typeof(Vector2)); // I am removing the "as Vector2[]" as it has no effect
但是,总体而言,这是一个低效的解决方案,因为阵列在组合期间需要多次调整大小,然后再进行转换。为什么不立即创建具有正确类型和大小的数组
Array CreateTerrainVertices(float[] _heightmap, float _resolution)
{
Debug.Log("Creating terrain vertices");
// The minimum resolution is 1
resolution = Mathf.Max(1, resolution);
Vector2[] vertices = new Vector2[_heightmap.Length * 2];
// For each point, in the heightmap, create a vertex for
// the top and the bottom of the terrain.
for (int i = 0; i < _heightmap.Length; i++)
{
vertices[i * 2] = new Vector2(i / resolution, _heightmap[i]);
vertices[i * 2 + 1] = new Vector2(i / resolution, 0);
}
Debug.Log("Created " + vertices.length + " terrain vertices");
return vertices;
}
Array CreateTerrainVertices(float[]\u高度映射,float\u分辨率)
{
Log(“创建地形顶点”);
//最小分辨率为1
分辨率=数学最大值(1,分辨率);
Vector2[]顶点=新Vector2[_heightmap.Length*2];
//在高度贴图中,为每个点创建顶点
//地形的顶部和底部。
对于(int i=0;i<\u heightmap.Length;i++)
{
顶点[i*2]=新向量2(i/分辨率,_高度映射[i]);
顶点[i*2+1]=新矢量2(i/分辨率,0);
}
Log(“已创建”+顶点.length+“地形顶点”);
返回顶点;
}
这是JavaScript还是C代码?这是JavaScript还是C代码?