Advertisement
Bcadren

Skateboard

Apr 18th, 2015
451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var newVertices : Vector3[];
  2. var newUV : Vector2[];
  3. var newTriangles : int[];
  4. var triangles : Array;
  5. var UVs : Array;
  6. var vertices : Array;
  7. var width : float;
  8. var length : float;
  9. var depth : float;
  10. var duckHeight : float;
  11. private var currentLength : int;
  12.  
  13. function Start () {
  14.     UVs = new Array ();
  15.     newVertices = [Vector3(0,0,0), Vector3(0,0,width), Vector3(length,0,0), Vector3(length,0,width), Vector3(0,0,width/2),
  16.    
  17.         Vector3((width/2)*(0+Mathf.Sin(Mathf.Deg2Rad*(0-30))),duckHeight/3,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(0-30)))),
  18.         Vector3((width/2)*(0+Mathf.Sin(Mathf.Deg2Rad*(0-60))),2*duckHeight/3,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(0-60)))),
  19.         Vector3((width/2)*(0+Mathf.Sin(Mathf.Deg2Rad*(0-90))),duckHeight,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(0-90)))),
  20.         Vector3((width/2)*(0+Mathf.Sin(Mathf.Deg2Rad*(0-120))),2*duckHeight/3,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(0-120)))),
  21.         Vector3((width/2)*(0+Mathf.Sin(Mathf.Deg2Rad*(0-150))),duckHeight/3,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(0-150)))),
  22.        
  23.         Vector3(length,0,width/2),
  24.         Vector3(length+(width/2)*(Mathf.Sin(Mathf.Deg2Rad*(30))),duckHeight/3,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(30)))),
  25.         Vector3(length+(width/2)*(Mathf.Sin(Mathf.Deg2Rad*(60))),2*duckHeight/3,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(60)))),
  26.         Vector3(length+(width/2)*(Mathf.Sin(Mathf.Deg2Rad*(90))),duckHeight,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(90)))),
  27.         Vector3(length+(width/2)*(Mathf.Sin(Mathf.Deg2Rad*(120))),2*duckHeight/3,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(120)))),
  28.         Vector3(length+(width/2)*(Mathf.Sin(Mathf.Deg2Rad*(150))),duckHeight/3,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(150))))
  29.        
  30. ];  currentLength = newVertices.Length;
  31.     vertices = Array(newVertices);
  32.     for (j=0; j<currentLength; j++)
  33.         vertices.Add(Vector3(newVertices[j].x,newVertices[j].y-depth,newVertices[j].z));
  34.     newVertices = vertices.ToBuiltin(Vector3);
  35.     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,
  36.         2,10,15, 15,10,14, 14,10,13, 13,10,12, 12,10,11, 11,10,3 ];
  37.     currentLength = (newTriangles.Length/3);
  38.     triangles = Array(newTriangles);
  39.     for (k=0; k< currentLength; k++){
  40.         triangles.Add(newTriangles[k*3]+16);   
  41.         triangles.Add(newTriangles[k*3+2]+16);
  42.         triangles.Add(newTriangles[k*3+1]+16); 
  43. }   triangles.Add(0,2,16, 18,16,2,
  44.         2,15,18, 18,15,31,
  45.         15,14,31, 31,14,30,
  46.         14,13,30, 30,13,29,
  47.         13,12,28, 13,28,29,
  48.         12,11,27, 12,27,28,
  49.         11,3,19, 11,19,27,
  50.         3,1,19, 1,17,19,
  51.         1,5,21, 1,21,17,
  52.         5,6,22, 21,5,22,
  53.         6,23,22, 23,6,7,
  54.         23,7,24, 24,7,8,
  55.         8,25,24, 25,8,9,
  56.         16,25,9, 16,9,0);
  57.     newTriangles = triangles.ToBuiltin(int);
  58.     for (i=0; i< newVertices.length; i++)
  59.         UVs.Add (Vector2(0,0));
  60.     newUV = UVs.ToBuiltin(Vector2);
  61.     var mesh : Mesh = new Mesh ();
  62.     GetComponent.<MeshFilter>().mesh = mesh;
  63.     mesh.vertices = newVertices;
  64.     mesh.uv = newUV;
  65.     mesh.triangles = newTriangles;
  66.     mesh.RecalculateNormals();
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement