当前位置:网站首页>Unity grid programming 06

Unity grid programming 06

2022-06-23 08:48:00 LittleU

Now that we have completed a triangle, let's refer to the previous , Write another triangle , And put this patch together into a quadrilateral , Just refer to the previous code directly , And to make it easy to see , Slightly adjust the position of the second triangle .

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

// Script dependencies on components 
[RequireComponent(typeof(MeshFilter),typeof(MeshRenderer))]

public class SimpleProceduralMesh : MonoBehaviour
{
    private void OnEnable()
    {

        Mesh mesh = new Mesh()
        {
            name = "Procedural Mesh"
        };

        //3 vertices 
        mesh.vertices = new Vector3[] {
            Vector3.zero ,
            Vector3 .right ,
            Vector3 .up ,
            new Vector3 (1.1f,0),
            new Vector3 (1.1f,1.1f),
            new Vector3 (0,1.1f)
        };
        // Render order of vertices 
        mesh.triangles = new int[] {
            0,2,1,
            5,4,3
        };
        // Model Discovery orientation 
        mesh.normals = new Vector3[] {
            Vector3 .back,
            Vector3 .back,
            Vector3 .back,
            Vector3 .back,
            Vector3 .back,
            Vector3 .back

        };
        // Model UV
        mesh.uv = new Vector2[] {
            Vector2 .zero,
            Vector2.right,
            Vector2.up ,
            new Vector3 (1.1f,0),
            new Vector3 (1.1f,1.1f),
            new Vector3 (0,1.1f)
        };

        mesh.tangents = new Vector4[] {
            new Vector4(1f,0f,0f,-1f),
            new Vector4(1f,0f,0f,-1f),
            new Vector4(1f,0f,0f,-1f),
            new Vector4(1f,0f,0f,-1f),
            new Vector4(1f,0f,0f,-1f),
            new Vector4(1f,0f,0f,-1f)
        };

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

    
}

So run again unity Program :

原网站

版权声明
本文为[LittleU]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/01/202201081638593315.html