Created
April 19, 2017 18:16
-
-
Save CovorSorin/68eba424c02c7184be96fe6a0466cf3c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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