Saving screenshots from the game
In this recipe, we will learn how to take in-game snapshots, and save them in an external file. Better yet, we will make it possible to choose between three different methods.
Note
This technique only works when you compile to a Windows or Mac standalone executable—it will not work for Web Player builds, for example.
Getting ready
In order to follow this recipe, please import the screenshots
package, which is available in the 1362_10_06
folder, to your project. The package includes a basic terrain, and a camera that can be rotated via mouse.
How to do it...
To save the screenshots from your game, follow these steps:
- Import the
screenshots
package and open thescreenshotLevel
scene. - Add the following C# Script to the Main Camera:
using UnityEngine; using System.Collections; using System; using System.IO; public class TakeScreenshot : MonoBehaviour { public string prefix = "Screenshot"; public enum method{captureScreenshotPng, ReadPixelsPng, ReadPixelsJpg...