I wanted to add a screenshot taker in my unity project, but what surprised me was when I compiled it and ran it, there was nothing new in my application folder. I used 3 diffrent methods to try and save a screenshot, but nothing worked.
I moved the script onto my main camera to test it out, and I get lag every time it takes a screenshot, but there is no file at all. Is it just me or is it a known problem or something? Heres the code:
function Update () {
//if user presses PrintScreen take a screenshot
if(Input.GetKeyDown(KeyCode.Print)) {
PRINTSCREEN();
}
else if (Input.GetKeyDown(KeyCode.Escape)) {
Application.Quit();
}
}
function PRINTSCREEN() {
yield WaitForEndOfFrame();
var SCREENSHOT = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
SCREENSHOT.ReadPixels(Rect(0,0,Screen.width, Screen.height),0,0);
SCREENSHOT.Apply();
var SCRN = SCREENSHOT.EncodeToPNG();
Destroy(SCREENSHOT);
//Doesn't work
//Application.CaptureScreenshot(Application.dataPath + "/Screenshot.png");
//Also doesn't work
//var ENCSCRN:System.IO.BinaryWriter = new System.IO.BinaryWriter(System.IO.File.Open(Application.dataPath + "/Screenshot.png", System.IO.FileMode.Create));
//ENCSCRN.Write(SCRN);
//ENCSCRN.Close();
//Also doesn't work
System.IO.File.WriteAllBytes(Application.dataPath + "/Screenshots.png",SCRN);
}