Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1.     void LateUpdate()
  2.     {
  3.         if (snapCam.gameObject.activeInHierarchy)
  4.         {
  5.             Texture2D snapshot = new Texture2D(resWidth, resHeight, TextureFormat.RGB24, false);
  6.             snapCam.Render();
  7.             RenderTexture.active = snapCam.targetTexture;
  8.  
  9.             snapshot.ReadPixels(new Rect(0, 0, resWidth, resHeight), 0, 0);
  10.             byte[] bytes = snapshot.EncodeToPNG();
  11.             string filename = SnapshotName();
  12.             System.IO.File.WriteAllBytes(filename, bytes);
  13.  
  14.  
  15.             if (count == 50)
  16.             {
  17.                 count = 0;
  18.             }
  19.             snapCam.gameObject.SetActive(false);
  20.         }
  21.     }
  22.     string SnapshotName()
  23.     {
  24.         count++;
  25.         return string.Format("{0}/Resources/{1}.png",
  26.             Application.dataPath,
  27.             count);
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement