Created
November 7, 2014 23:04
-
-
Save alchemycs/8c9ea06e5c4242c6305f to your computer and use it in GitHub Desktop.
Bind a key to take a screen shot for
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 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