Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我可以创建一个网格(在唤醒中),但我看不到它_C#_Unity3d - Fatal编程技术网

C# 我可以创建一个网格(在唤醒中),但我看不到它

C# 我可以创建一个网格(在唤醒中),但我看不到它,c#,unity3d,C#,Unity3d,这是生成网格的代码部分,如果需要更多信息,请询问。 因此,在场景中我看不到它,我试图进入播放模式,但什么都没有,如果我进入检查器,我可以看到:4个顶点,2个tris,正确数量的tris和verts public void ConstructMesh() { Vector3[] vertices = new Vector3[(resolution + 2) * (resolution + 2)]; int[] triangles = new int[(re

这是生成网格的代码部分,如果需要更多信息,请询问。 因此,在场景中我看不到它,我试图进入播放模式,但什么都没有,如果我进入检查器,我可以看到:4个顶点,2个tris,正确数量的tris和verts

 public void ConstructMesh()
    {
        Vector3[] vertices = new Vector3[(resolution + 2) * (resolution + 2)];
        int[] triangles = new int[(resolution + 1) * (resolution + 1) * 6];
        int triIndex = 0;

        for (int y = 0; y < resolution; y++)
        {
            for (int x = 0; x < resolution; x++)
            {
                int i = x + y * resolution;
                Vector2 percent = new Vector2(x, y) / (resolution - 1);
                Vector3 pointOnUnitCode = localUp + (percent.x - .5f) * 2 * axisA + (percent.y - .5f) * 2 * axisB;
                vertices[i] = pointOnUnitCode;

                triangles[triIndex] = i;
                triangles[triIndex + 1] = i + resolution + 1;
                triangles[triIndex + 2] = i + resolution;

                triangles[triIndex + 3] = i;
                triangles[triIndex + 4] = i + 1;

                triangles[triIndex + 5] = i + resolution + 1;
                 triIndex += 6;
            }
        }
        planet.Clear();
        planet.vertices = vertices;
        planet.triangles = triangles;
        planet.RecalculateNormals();
    }
public void ConstructMesh()
{
向量3[]顶点=新向量3[(分辨率+2)*(分辨率+2)];
int[]三角形=新int[(分辨率+1)*(分辨率+1)*6];
int-triIndex=0;
对于(int y=0;y<分辨率;y++)
{
对于(int x=0;x
您需要游戏对象中的网格渲染器和网格过滤器才能渲染网格

假设您的方法ConstructMesh是一个MonoBehavior,并且它附加到要显示网格的同一对象,则可以执行以下操作:

GetComponent<MeshFilter>().mesh = planet;
GetComponent().mesh=planet;

是否将网格指定给任何
MeshRenderer
组件?是的,但我解决了,谢谢。