Skip to content

Instantly share code, notes, and snippets.

@m0nsky
Last active September 7, 2023 17:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save m0nsky/1a41a56743b54c559010412e77137e2d to your computer and use it in GitHub Desktop.
Save m0nsky/1a41a56743b54c559010412e77137e2d to your computer and use it in GitHub Desktop.
Screenshotter
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Screenshotter : MonoBehaviour
{
// Seconds to wait before taking a screenshot
public float waitTime = 5f;
// Seconds that we have waited so far
private float _waitedTime = 0f;
// Screenshot filename prefix
public string filenamePrefix = "example_project";
// Path to save the screenshots to
public string path = "Assets/Screenshots/";
// Amount of degrees to rotate per step
public Vector3 rotationStep = new Vector3(0f, 0f, 0f);
// Amount of units to move per step
public Vector3 movementStep = new Vector3(0f, 0f, 0f);
// Total number of screenshots to take
public int totalScreenshots = 18;
// Total number of screenshots taken so far
private int _takenScreenshots = 0;
// Update function
void Update()
{
// Add the time since the last frame to waitedTime
_waitedTime += Time.deltaTime;
// If we have waited long enough
if (_waitedTime >= waitTime && _takenScreenshots < totalScreenshots)
{
// Filename
string filename = filenamePrefix + "_" + _takenScreenshots + ".png";
// Take a screenshot, and save it to the path
ScreenCapture.CaptureScreenshot(path + filename);
// Increment takenScreenshots
_takenScreenshots++;
// Log a message to the console
Debug.Log("Screenshot " + _takenScreenshots + " of " + totalScreenshots + " saved to [" + path + filename + "]");
// Rotate the object by the rotation steps
transform.Rotate(rotationStep);
// Move the object by the movement steps
transform.Translate(movementStep);
// Reset waitedTime
_waitedTime = 0f;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment