Skip to content

Instantly share code, notes, and snippets.

@Maoyeedy
Last active October 14, 2023 08:49
Show Gist options
  • Save Maoyeedy/168e978f7a160b4e0a6431525358ad0b to your computer and use it in GitHub Desktop.
Save Maoyeedy/168e978f7a160b4e0a6431525358ad0b to your computer and use it in GitHub Desktop.
A minimal Unity screenshot script
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