原地址:http://www.cnblogs.com/88999660/archive/2013/01/21/2869747.html

void OnGUI(){

        if(GUI.Button(new Rect(10,70,50,50),"ScreenShot")){
StartCoroutine(ScreenShot()); //协程调用
}
} IEnumerator ScreenShot(){
int width = Screen.width;
int height = Screen.height;
yield return new WaitForEndOfFrame(); //去掉协程试试看会发生什么。
Texture2D tex = new Texture2D(width,height,TextureFormat.RGB24,false);//设置Texture2D
tex.ReadPixels(new Rect(0,0,width,height),0,0);//获取Pixels
tex.Apply();//应用改变
byte[] bytes = tex.EncodeToPNG();//转换为byte[]
       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(); }

  另一种方法:

using UnityEngine; 

using System.Collections;

public class example : MonoBehaviour 

{ 

  void OnMouseDown() 

  { 

    Application.CaptureScreenshot("Screenshot.png"); 

  } 

}

function OnGUI(){
if(GUI.Button(Rect(Screen.width*0.5-,Screen.height*0.5-,,),"screen")){
Application.CaptureScreenshot("Screenshot.png");
}
}

这张Screenshot.png图片被存在了当前工程的子目录下了。

最新文章

  1. <转> jsp:include 乱码问题解决
  2. 解析Javascript中大括号“{}”的多义性
  3. WriteFile实现下载
  4. Eclipse 文本显示行号
  5. TweenMax动画库学习(三)
  6. 利用动软代码生成器 自动生成LINQ需要用的数据实体类 (转)
  7. c、c++混编实现查询本地IP地址
  8. 【线段树】BAPC2014 E Excellent Engineers (Codeforces GYM 100526)
  9. .parents() 与 .parent()对比
  10. USACO Section 1.1-2 Greedy Gift Givers
  11. 3_Longest Substring Without Repeating Characters -- LeetCode
  12. sololearn的c++学习记录_4m11d
  13. 菜鸟脱壳之脱壳的基础知识(五)——利用内存断点寻找OEP
  14. 通过linux核映射驱动访问GPIO
  15. ubuntu ssh前后台切换命令相关
  16. 国内阿里云Maven镜像(速度飞起)
  17. appscan 9.0.3.10 版本下载
  18. 把XML保存为ANSI编码
  19. C语言字节对齐问题详解(对齐、字节序、网络序等)
  20. ASP.Net Core MVC 网站在Windows服务器跑不起来

热门文章

  1. 2016 版 Laravel 系列入门教程(五)【最适合中国人的 Laravel 教程】
  2. VS2013打开项目提示此版本的应用程序不支持其项目类型(.csproj)
  3. Erlang之父的学习历史及学习建议
  4. Robot Framework测试框架学习笔记
  5. (转)eclipse项目导入到android studio中
  6. Using a Comparison Function for the Key Type
  7. HackerRank and MiniMax
  8. Maven学习笔记-03-Eclipse下maven项目在Tomcat7和Jetty6中部署调试
  9. Python初学笔记
  10. Color Space