Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1.  
  2. public class GraphicsMeshSample : MonoBehaviour {
  3. static public Material material;
  4. static public Mesh meshCache = null;
  5.  
  6. void Update () {
  7. Vector3 position = transform.position;
  8. Quaternion rotation = transform.rotation;
  9. Vector3 scale = transform.lossyScale;
  10. Matrix4x4 matrix = Matrix4x4.TRS(position, rotation, scale);
  11.  
  12. Graphics.DrawMesh(GetMesh(), matrix, material, 0);
  13. }
  14.  
  15. static public Mesh GetMesh() {
  16. if (meshCache == null) {
  17. meshCache = new Mesh();
  18. int size = 1;
  19.  
  20. meshCache.vertices = new Vector3[] {
  21. new Vector3(-size, -size, 0.01f),
  22. new Vector3(-size, size, 0.01f),
  23. new Vector3(size, size, 0.01f),
  24. new Vector3(size, -size, 0.01f)
  25. };
  26.  
  27.  
  28. meshCache.uv = new Vector2[] {
  29. new Vector2 (0, 0),
  30. new Vector2 (0, 1),
  31. new Vector2(1, 1),
  32. new Vector2 (1, 0)
  33. };
  34. meshCache.triangles = new int[] { 0, 1, 2, 0, 2, 3};
  35. meshCache.RecalculateNormals();
  36. }
  37.  
  38. return(meshCache);
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement