Saving screenshots and RenderTextures to files
At each point in time, a RenderTexture contains an image – a screenshot from the point of view of the Camera rendering to that RenderTexture. Games can have features such as snapshots at exciting points in time, such as crossing a finish line, landing a difficult jump, or taking the lead in a race. Through scripting we can take the picture data from the RenderTexture and save it as an image file.
Also, if you simply want to be able to take a snapshot of the Game screen (Main Camera view) at any point during the game as a PNG file, this is something Unity has made really easy too. We’ll explore both these features in this recipe.
Figure 13.25: PNG screenshot image of Main Camera view taken while playing the game
Getting ready
This project follows on from the previous one, so make a copy of that one to work on in this recipe. Note – many thanks to krzys-h for posting the RenderTexture-to-image file...