Take snapshot of game scene

Hello, in games like Jetpack joyride and hill climb racing at the end of the game the game takes a screenshot of the last event you did before game over.My question is can this be achieved in unity and how?

1 Answer

1

It is possible. Follow this post to understand how to create a screenshot: How to save a picture (take screenshot) from a camera in game? - Unity Answers

After this you only need to set up a mechanism, to call it before game over occurs.

K, I found a way witch I tested in unity editor. I hope it will work on build version too. So first of all you need a code snippet like this:

//place this in the OnGui() method 
		if(GUI.Button(new Rect(Screen.width/3, Screen.height/5, Screen.width/3,Screen.height/10),"print"))
		{
		    PrintDocument pd = new PrintDocument();
			pd.PrintPage += PrintPage;
			pd.Print();  	
		}
 // place this in the same class
	private void PrintPage(object o, PrintPageEventArgs e)
	{
		System.Drawing.Image img = System.Drawing.Image.FromFile("D:\\Foto.jpg");
		Point loc = new Point(100, 100);
		e.Graphics.DrawImage(img, loc);     
	}

You need to include System.Drawing and System.Drawing.Printing; in your class. It will say there is no Drawing namespace in your System, so for that to fix you need to go to your unity folder and search for system.drawing.dll and copy it to your asset folder.

Now if you have the screenshot saved out to a file, change the acces to it and you are ready to go. Good luck with it. If you tried it out on build please let me know, I only had time to test in editor mode.

thanks for this......what if i wanted to print it how would i go about that?

Like send it to printer? Well the easiest way is to print out the png, you get from the screenshot :) About scripting it's a bit harder question, what platform are you using?

yeah send to printer.....am using a PC

Edited the answer for better visibility.

ok thanks am away from my pc now but will definitely let u know when i test this