I have attached the following code below to my camera and am able to take a screenshot by hitting the letter K.
But how would I rework it to take a screenshot when the player clicks on a GUI button?
Thank you for your input!
var resWidth : int = 4096;
var resHeight : int = 2232;
if (Input.GetKeyDown ("k"))
var rt = new RenderTexture(resWidth, resHeight, 24);
camera.targetTexture = rt;
var screenShot = new Texture2D(resWidth, resHeight, TextureFormat.RGB24, false);
RenderTexture.active = rt;
screenShot.ReadPixels(Rect(0, 0, resWidth, resHeight), 0, 0);
RenderTexture.active = null; // JC: added to avoid errors
camera.targetTexture = null;
var bytes = screenShot.EncodeToPNG();
System.IO.File.WriteAllBytes(Application.dataPath + "/screenshots/screen" + System.DateTime.Now.ToString("dd-MM-yyyy_HH-mm-ss") + ".png", bytes);
Feb 06 '11 at 01:11 AM