Skip to content

Instantly share code, notes, and snippets.

@kurtdekker
Created January 10, 2022 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurtdekker/d93d82c783510c16e7e85e30e3656052 to your computer and use it in GitHub Desktop.
Save kurtdekker/d93d82c783510c16e7e85e30e3656052 to your computer and use it in GitHub Desktop.
take simple screenshots in Unity3D
using UnityEngine;
using System.Collections;
// @kurtdekker
// drop it in a scene somewhere or else call PossiblyAttach(),
// in which case it only attaches in the editor.
public class EditorScreenshotTaker : MonoBehaviour
{
static bool tried;
public static void PossiblyAttach()
{
if (tried) return;
tried = true;
if (Application.isEditor)
{
EditorScreenshotTaker est = new GameObject(
"EditorScreenshotTaker().PossiblyAttach();").
AddComponent<EditorScreenshotTaker>();
DontDestroyOnLoad( est.gameObject);
}
}
void Update ()
{
if (Input.GetKeyDown( KeyCode.BackQuote))
{
string filename = System.String.Format(
// replace this path with where you want it to go:
"/Users/kurt/Desktop/" +
// and replace this if you want something else
"Screenshot-Hovercar-{0}.png", System.DateTime.Now.ToFileTime());
Debug.Log ( filename);
ScreenCapture.CaptureScreenshot( filename);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment