Skip to content

Instantly share code, notes, and snippets.

@grimmdev
Created October 24, 2014 02:29
Show Gist options
  • Save grimmdev/2a6fd3a068a938dc8f38 to your computer and use it in GitHub Desktop.
Save grimmdev/2a6fd3a068a938dc8f38 to your computer and use it in GitHub Desktop.
Simple class for Screenshots in Unity, no need to attach it to any object, just call the Capture function and use, contains 2 constructors.
using UnityEngine;
using System.Collections;
public static class Screenshot
{
private static string GetTimestamp () {
System.DateTime dateTime = System.DateTime.Now;
return dateTime.ToString("yyyyMMddHHmmss");
}
private static string GetPath () {
return Application.dataPath + "/";
}
private static string namePrefix = "Screenshot"; // Before the timestamp // Example "Gametitle_"
private static string nameSuffix = ""; // After the timestamp
// Default Capture
// use like so Screenshot.Capture();
public static void Capture () {
string fullPath = GetPath() + namePrefix + GetTimestamp() + nameSuffix + ".png";
Application.CaptureScreenshot (fullPath);
Debug.Log ("Capured Screenshot: "+ fullPath);
}
// Capture with Custom Name
// use like so Screenshot.Capture("FileNameHere");
public static void Capture (string name) {
string fullPath = GetPath() + name + ".png";
Application.CaptureScreenshot (fullPath);
Debug.Log ("Capured Screenshot: "+ fullPath);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment