Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class MakeMesh : MonoBehaviour {
- MeshFilter filter;
- MeshRenderer renderer;
- Mesh mesh;
- public Material material;
- // Use this for initialization
- void Start () {
- filter = gameObject.AddComponent<MeshFilter>();
- renderer = gameObject.AddComponent<MeshRenderer>();
- mesh = new Mesh();
- filter.mesh = mesh;
- int numQuads = 4000;
- int numVerts = (numQuads+1) * 2;
- Vector3[] verts = new Vector3[ numVerts ];
- int v = 0;
- for (int n=0; n<=numQuads; ++n)
- {
- verts[v++] = new Vector3( -1, Mathf.Sin(n*.1f), n * 1 );
- verts[v++] = new Vector3( 1, Mathf.Sin((n*.1f)+Mathf.PI), n * 1 );
- }
- int numTris = numQuads*2;
- int[] tris = new int[ numTris * 3 ];
- int ti = 0;
- for (int triNum=0; triNum<numTris; triNum += 2)
- {
- tris[ti++] = triNum;
- tris[ti++] = triNum+3;
- tris[ti++] = triNum+1;
- tris[ti++] = triNum;
- tris[ti++] = triNum+2;
- tris[ti++] = triNum+3;
- }
- mesh.vertices = verts;
- mesh.triangles = tris;
- renderer.material = material;
- mesh.RecalculateNormals();
- }
- // Update is called once per frame
- void Update () {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment