Hello Everyone! 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!
K.
var resWidth : int = 4096;
var resHeight : int = 2232;
function Update()
{
if (Input.GetKeyDown ("k"))
{
var rt = new RenderTexture(resWidth, resHeight, 24);
camera.targetTexture = rt;
var screenShot = new Texture2D(resWidth, resHeight, TextureFormat.RGB24, false);
camera.Render();
RenderTexture.active = rt;
screenShot.ReadPixels(Rect(0, 0, resWidth, resHeight), 0, 0);
RenderTexture.active = null; // JC: added to avoid errors
camera.targetTexture = null;
Destroy(rt);
var bytes = screenShot.EncodeToPNG();
System.IO.File.WriteAllBytes(Application.dataPath + "/screenshots/screen" + System.DateTime.Now.ToString("dd-MM-yyyy_HH-mm-ss") + ".png", bytes);
}
}