void OnGUI(){
//第一种方法 if(GUI.Button(new Rect(10,70,50,50),"ScreenShot")){ StartCoroutine(ScreenShot()); }
//第二种方法
if(GUI.Button(Rect(Screen.width*0.5-50,Screen.height*0.5-50,100,100),"screen")){ Application.CaptureScreenshot("Screenshot.png"); }}
IEnumerator ScreenShot(){
int width = Screen.width;
int height = Screen.height;
yield return new WaitForEndOfFrame();
Texture2D tex = new Texture2D(width,height,TextureFormat.RGB24,false);
tex.ReadPixels(new Rect(0,0,width,height),0,0);
tex.Apply();
byte[] bytes = tex.EncodeToPNG();
Destroy(tex);
Stream flstr = new FileStream(@"d:\1.png", FileMode.Create);
BinaryWriter sw = new BinaryWriter(flstr, Encoding.Unicode);
sw.Write(bytes);
sw.Close();
flstr.Close();
}