Advertisement
Guest User

ChangeUV

a guest
Aug 20th, 2013
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. All credit for this code goes to cgaudino. I just rewrote his function in js and made some minor changes.
  3. Don't forget to change the scale:Vector2 values to match your spritesheet. Ideally it should be passed on the function arguments.
  4. */
  5.  
  6. function ChangeUV(plane:GameObject, offset:Vector2)
  7. {
  8.     //Modify quad uvs
  9.     var spriteMesh:Mesh = plane.GetComponent(MeshFilter).mesh;
  10.     var scale:Vector2 = Vector2(0.125, 0.25);
  11.     var uvs:Vector2[] = new Vector2[4];
  12.     uvs[0].x = offset.x;
  13.     uvs[0].y = offset.y - scale.y;
  14.     uvs[1].x = offset.x + scale.x;
  15.     uvs[1].y = offset.y;
  16.     uvs[2].x = offset.x + scale.x;
  17.     uvs[2].y = offset.y - scale.y;
  18.     uvs[3].x = offset.x;
  19.     uvs[3].y = offset.y;
  20.    
  21.     spriteMesh.uv = uvs;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement