By the way, if you simply want to be able to take a snapshot of the game screen during the game as a PNG file, this is something Unity has made really easy. Create a script class such as the following, and add an instance as a component to any GameObject (or create a new Empty GameObject to hold the script instance):
using UnityEngine;
using System;
public class Snapshot : MonoBehaviour {
void Update() {
if (Input.GetKeyUp(KeyCode.P)) {
print("taking snapshot");
string timeStamp = DateTime.Now.ToString("HH_mm_ss");
ScreenCapture.CaptureScreenshot("snapshot_" + timeStamp + ".png");
}
}
}
Of course, you can change which KeyCode and what filename your image is saved as by editing the script. The PNG snapshot file will be created outside your Assets folder where your Unity project is stored:
Figure 11.17 – A PNG snapshot...