Created
March 23, 2019 14:18
-
-
Save huihut/51e9aee56c75e7eab72810189ab73e41 to your computer and use it in GitHub Desktop.
Unity TakeScreenshot
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
// <http://wiki.unity3d.com/index.php?title=TakeScreenshot> | |
// TODO: | |
// By default, screenshot files are placed next to the executable bundle -- we don't want this in a | |
// shipping game, as it will fail if the user doesn't have write access to the Applications folder. | |
// Instead we should place the screenshots on the user's desktop. However, the ~/ notation doesn't | |
// work, and Unity doesn't have a mechanism to return special paths. Therefore, the correct way to | |
// solve this is probably with a plug-in to return OS specific special paths. | |
// Mono/.NET has functions to get special paths... see discussion page. --Aarku | |
using UnityEngine; | |
using System.Collections; | |
public class TakeScreenshot : MonoBehaviour | |
{ | |
private int screenshotCount = 0; | |
// Check for screenshot key each frame | |
void Update() | |
{ | |
// take screenshot on up->down transition of F9 key | |
if (Input.GetKeyDown("f9")) | |
{ | |
string screenshotFilename; | |
do | |
{ | |
screenshotCount++; | |
screenshotFilename = "screenshot" + screenshotCount + ".png"; | |
} while (System.IO.File.Exists(screenshotFilename)); | |
Application.CaptureScreenshot(screenshotFilename); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment