Last active
October 14, 2023 08:49
-
-
Save Maoyeedy/168e978f7a160b4e0a6431525358ad0b to your computer and use it in GitHub Desktop.
A minimal Unity screenshot script
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 System; | |
using System.IO; | |
using UnityEngine; | |
public class ScreenshotScript : MonoBehaviour | |
{ | |
public string folderPath = Path.Combine(Application.dataPath, "..", "SampleRecordings"); | |
public KeyCode captureKey = KeyCode.Tab; | |
private void Start() | |
{ | |
Directory.CreateDirectory(folderPath); | |
} | |
private void Update() | |
{ | |
if (!Input.GetKeyDown(captureKey)) return; | |
string filename = DateTime.Now.ToString("yyyy.MM.dd-HH.mm.ss") + ".png"; | |
string filePath = Path.Combine(folderPath, filename); | |
ScreenCapture.CaptureScreenshot(filePath); | |
print("Screenshot saved: " + filePath); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment