Skip to content

Instantly share code, notes, and snippets.

@CovorSorin
Created April 19, 2017 18:16
Show Gist options
  • Save CovorSorin/68eba424c02c7184be96fe6a0466cf3c to your computer and use it in GitHub Desktop.
Save CovorSorin/68eba424c02c7184be96fe6a0466cf3c to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
// Attach this script to a camera.
public class Screenshooter : MonoBehaviour {
int imgNumber;
public int upscale = 2;
void Start () {
// Get the last screenshot number.
if (File.Exists(@"E:\screenshot.txt")){
string text = System.IO.File.ReadAllText(@"E:\screenshot.txt");
imgNumber = int.Parse(text);
}
else{
imgNumber = 0;
}
}
void LateUpdate () {
takeScreenshot ();
}
void takeScreenshot(){
if (Input.GetKeyDown (KeyCode.K)) {
imgNumber++;
string path = @"Assets/Screenshots/screenshot" + imgNumber + ".png";
Application.CaptureScreenshot (path, upscale);
Debug.Log ("Screenshot " + imgNumber.ToString() + " taken");
// Write to the text file.
System.IO.File.WriteAllText (@"E:\screenshot.txt", imgNumber.ToString());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment