Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var newVertices : Vector3[];
- var newUV : Vector2[];
- var newTriangles : int[];
- var triangles : Array;
- var UVs : Array;
- var vertices : Array;
- var width : float;
- var length : float;
- var depth : float;
- var duckHeight : float;
- private var currentLength : int;
- function Start () {
- UVs = new Array ();
- newVertices = [Vector3(0,0,0), Vector3(0,0,width), Vector3(length,0,0), Vector3(length,0,width), Vector3(0,0,width/2),
- Vector3((width/2)*(0+Mathf.Sin(Mathf.Deg2Rad*(0-30))),duckHeight/3,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(0-30)))),
- Vector3((width/2)*(0+Mathf.Sin(Mathf.Deg2Rad*(0-60))),2*duckHeight/3,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(0-60)))),
- Vector3((width/2)*(0+Mathf.Sin(Mathf.Deg2Rad*(0-90))),duckHeight,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(0-90)))),
- Vector3((width/2)*(0+Mathf.Sin(Mathf.Deg2Rad*(0-120))),2*duckHeight/3,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(0-120)))),
- Vector3((width/2)*(0+Mathf.Sin(Mathf.Deg2Rad*(0-150))),duckHeight/3,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(0-150)))),
- Vector3(length,0,width/2),
- Vector3(length+(width/2)*(Mathf.Sin(Mathf.Deg2Rad*(30))),duckHeight/3,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(30)))),
- Vector3(length+(width/2)*(Mathf.Sin(Mathf.Deg2Rad*(60))),2*duckHeight/3,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(60)))),
- Vector3(length+(width/2)*(Mathf.Sin(Mathf.Deg2Rad*(90))),duckHeight,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(90)))),
- Vector3(length+(width/2)*(Mathf.Sin(Mathf.Deg2Rad*(120))),2*duckHeight/3,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(120)))),
- Vector3(length+(width/2)*(Mathf.Sin(Mathf.Deg2Rad*(150))),duckHeight/3,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(150))))
- ]; currentLength = newVertices.Length;
- vertices = Array(newVertices);
- for (j=0; j<currentLength; j++)
- vertices.Add(Vector3(newVertices[j].x,newVertices[j].y-depth,newVertices[j].z));
- newVertices = vertices.ToBuiltin(Vector3);
- newTriangles = [0,1,3, 0,3,2, 0,9,4, 5,4,6, 6,4,7, 7,4,8, 8,4,9, 5,1,4,
- 2,10,15, 15,10,14, 14,10,13, 13,10,12, 12,10,11, 11,10,3 ];
- currentLength = (newTriangles.Length/3);
- triangles = Array(newTriangles);
- for (k=0; k< currentLength; k++){
- triangles.Add(newTriangles[k*3]+16);
- triangles.Add(newTriangles[k*3+2]+16);
- triangles.Add(newTriangles[k*3+1]+16);
- } triangles.Add(0,2,16, 18,16,2,
- 2,15,18, 18,15,31,
- 15,14,31, 31,14,30,
- 14,13,30, 30,13,29,
- 13,12,28, 13,28,29,
- 12,11,27, 12,27,28,
- 11,3,19, 11,19,27,
- 3,1,19, 1,17,19,
- 1,5,21, 1,21,17,
- 5,6,22, 21,5,22,
- 6,23,22, 23,6,7,
- 23,7,24, 24,7,8,
- 8,25,24, 25,8,9,
- 16,25,9, 16,9,0);
- newTriangles = triangles.ToBuiltin(int);
- for (i=0; i< newVertices.length; i++)
- UVs.Add (Vector2(0,0));
- newUV = UVs.ToBuiltin(Vector2);
- var mesh : Mesh = new Mesh ();
- GetComponent.<MeshFilter>().mesh = mesh;
- mesh.vertices = newVertices;
- mesh.uv = newUV;
- mesh.triangles = newTriangles;
- mesh.RecalculateNormals();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement