Created
January 10, 2022 19:25
-
-
Save kurtdekker/d93d82c783510c16e7e85e30e3656052 to your computer and use it in GitHub Desktop.
take simple screenshots in Unity3D
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; | |
// @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