duck

Untitled

Apr 26th, 2010
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var spray : GameObject;
  2. private var canSpray : boolean = true;
  3. private var numQuads = 10000;
  4. private var verts = new Vector3[numQuads * 4];
  5. private var uv = new Vector2[numQuads * 4];
  6. private var tris = new int[numQuads * 6];
  7. private var cv : int;
  8. var thecam : Camera;
  9. var mat : Material;
  10. private var mesh = new Mesh();
  11. private var matPropBlock = new MaterialPropertyBlock();
  12.  
  13. function Start () {
  14. for (var n=0; n< numQuads; ++n)
  15. {
  16.     tris[n*6 + 0] = n*4 + 0;
  17.     tris[n*6 + 1] = n*4 + 1;
  18.     tris[n*6 + 2] = n*4 + 2;
  19.     tris[n*6 + 3] = n*4 + 0;
  20.     tris[n*6 + 4] = n*4 + 2;
  21.     tris[n*6 + 5] = n*4 + 3;
  22.  
  23.     uv[n*4 + 0] = Vector2(0,0);
  24.     uv[n*4 + 1] = Vector2(0,1);
  25.     uv[n*4 + 2] = Vector2(1,1);
  26.     uv[n*4 + 3] = Vector2(1,0);
  27.  
  28. }
  29. GetComponent (MeshFilter).mesh = mesh;
  30. mesh.vertices = verts;
  31. mesh.uv = uv;
  32. mesh.triangles = tris;
  33.  
  34. }
  35.  
  36. function Update () {
  37.    
  38.     if(Input.GetButtonDown("Jump")){
  39.    
  40.         canSpray = false;  
  41.        
  42.     }else if(Input.GetButtonUp("Jump")){
  43.         canSpray=true;
  44.        
  45.     }
  46.    
  47.     if(canSpray){
  48.    
  49.         if(Input.GetButtonDown("Fire1")){
  50.    
  51.             InvokeRepeating("SprayIt", 0, 1);
  52.         }
  53.         if(Input.GetButtonUp("Fire1")){
  54.             CancelInvoke();
  55.         }
  56.     }
  57. }
  58.  
  59. function SprayIt(){
  60.    
  61.     var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
  62.     var hit : RaycastHit;
  63.     //var localPos = transform.InverseTransformPoint(hit.point);
  64.    
  65.     if (Physics.Raycast (ray, hit, 100)) {
  66.         //print ("Hit something");
  67.     }else{
  68.         //print ("No hit");
  69.     }
  70.      
  71.      if(hit.collider.gameObject.name == "Side"){
  72.        
  73.         print (cv);
  74.         verts[cv*4 + 0] = Vector3(0,0,0);
  75.         verts[cv*4 + 1] = Vector3(0,1,0);
  76.         verts[cv*4 + 2] = Vector3(1,1,0);
  77.         verts[cv*4 + 3] = Vector3(1,0,0);
  78.         print (verts[21]);
  79.         cv = cv + 1;
  80.        
  81.         DrawMesh(mesh, Vector3(0, 0, 0), Quaternion.identity, mat, 0, thecam, 0, matPropBlock);
  82.        
  83.         //print (hit.point.z);
  84.         //var theSpray : GameObject = Instantiate(spray, Vector3(hit.point.x, hit.point.y, hit.point.z), Quaternion.identity);
  85.             //theSpray.transform.up = hit.normal;    
  86.             //theSpray.transform.parent = hit.collider.gameObject.transform;
  87.      }
  88.  
  89.    
  90.    
  91. }
  92. function DrawMesh(mesh : Mesh, position : Vector3, rotation : Quaternion, material : Material, layer : int, camera : Camera, submeshIndex : int, properties : MaterialPropertyBlock) {
  93.    
  94. }
Advertisement
Add Comment
Please, Sign In to add comment