Skip to content

Instantly share code, notes, and snippets.

@alchemycs
Created November 7, 2014 23:04
Show Gist options
  • Save alchemycs/8c9ea06e5c4242c6305f to your computer and use it in GitHub Desktop.
Save alchemycs/8c9ea06e5c4242c6305f to your computer and use it in GitHub Desktop.
Bind a key to take a screen shot for
using UnityEngine;
using System.Collections;
public class ScreenShot : MonoBehaviour {
//Default is None, you should set this to whatever you want in the inspector
public KeyCode screenshotKey = KeyCode.None;
// Use this for initialization
void Start () {
if (screenshotKey == KeyCode.None)
{
Debug.LogWarning("No screenshot key assigned, disabling screenshot component");
enabled = false;
}
}
// Update is called once per frame
void Update () {
CheckForScreenshot();
}
void CheckForScreenshot()
{
if (Input.GetKeyUp(screenshotKey)) {
// string filename = "screenshot-" + System.DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss") + ".png";
string filename = "screenshot-" + System.DateTime.Now.ToString("yyyyMMddhhmmss") + ".png";
Application.CaptureScreenshot(filename);
//NOTE: If this is running in the unity editor the file will actually be saved in the root of the project
Debug.Log("Screenshot: " + Application.persistentDataPath + "/" + filename);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment