32 lines
734 B
C#
32 lines
734 B
C#
using System.IO;
|
|
using UnityEngine;
|
|
|
|
public class Screenshot : MonoBehaviour
|
|
{
|
|
public bool takeScreenshot;
|
|
public string filename = "unity_screenshot.png";
|
|
|
|
void Start()
|
|
{
|
|
if (takeScreenshot)
|
|
{
|
|
Camera cam = GetComponent<Camera>();
|
|
|
|
RenderTexture currentRT = RenderTexture.active;
|
|
RenderTexture.active = cam.targetTexture;
|
|
|
|
cam.Render();
|
|
|
|
Texture2D Image = new Texture2D(cam.targetTexture.width, cam.targetTexture.height);
|
|
Image.ReadPixels(new Rect(0, 0, cam.targetTexture.width, cam.targetTexture.height), 0, 0);
|
|
Image.Apply();
|
|
RenderTexture.active = currentRT;
|
|
|
|
var Bytes = Image.EncodeToPNG();
|
|
Destroy(Image);
|
|
|
|
File.WriteAllBytes("/home/crispypin/pictures/" + filename, Bytes);
|
|
}
|
|
}
|
|
|
|
}
|