unity的mesh和submesh

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NewBehaviourScript : MonoBehaviour
{
    public Vector3[] positions;
    public int[] triangles1;
    public int[] triangles2;
    public int[] triangles3;
    public Material[] materials;
    private Mesh mesh;
    private GameObject go;


    void Start()
    {
        mesh = new Mesh();
        mesh.name = "123";
        mesh.vertices = positions;
        go = new GameObject();
        MeshFilter mf = go.AddComponent<MeshFilter>();
        mf.mesh = mesh;
        MeshRenderer mr = go.AddComponent<MeshRenderer>();
        mesh.subMeshCount = 3;
        mr.materials = materials;
    }

    void Update()
    {
        if(Input.GetKeyDown(KeyCode.A))
        {
            mesh.SetTriangles(triangles1, 0);
        }
        if (Input.GetKeyDown(KeyCode.B))
        {
            mesh.SetTriangles(triangles2, 1);
        }
        if (Input.GetKeyDown(KeyCode.C))
        {
            mesh.SetTriangles(triangles3, 2);
        }
    }
}

在这里插入图片描述

在这里插入图片描述


版权声明:本文为wodownload2原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。