Skip to content

Instantly share code, notes, and snippets.

@miguelSantirso
Created January 30, 2016 15:26
Show Gist options
  • Save miguelSantirso/ca7dd6fe2bc97cc6470c to your computer and use it in GitHub Desktop.
Save miguelSantirso/ca7dd6fe2bc97cc6470c to your computer and use it in GitHub Desktop.
Unity: Press 'K' to take screenshots
using UnityEngine;
using System.Collections;
public class EasyScreenshot : MonoBehaviour
{
#region inspector properties
[SerializeField]
private int superSize = 1;
[SerializeField]
private string directory = "screenshots";
[SerializeField]
private string label = "default";
#endregion
public static string ScreenShotName(string directory, string tag)
{
var timestamp = System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss");
var relativePath = string.Format("{0}/{1}_{2}.png", directory, tag, timestamp);
var projectPath = System.IO.Path.GetDirectoryName(Application.dataPath);
return System.IO.Path.Combine(projectPath, relativePath);
}
void LateUpdate()
{
if (Input.GetKeyDown("k"))
{
var path = ScreenShotName(directory, label);
Debug.LogFormat("Capturing screenshot at: {0}", path);
Application.CaptureScreenshot(path, superSize);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment