728x90
ScreenShot.cs 라는 이름의 파일을 만들어 안에 소스를 넣어준다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | using System.Collections; using System.Collections.Generic; using UnityEngine; using System.IO; public class ScreenShot : MonoBehaviour { public Camera camera; //보여지는 카메라. private int resWidth; private int resHeight; string path; // Use this for initialization void Start () { resWidth = Screen.width; resHeight = Screen.height; path = Application.dataPath+"/ScreenShot/"; Debug.Log(path); } public void ClickScreenShot() { DirectoryInfo dir = new DirectoryInfo(path); if (!dir.Exists) { Directory.CreateDirectory(path); } string name; name = path + System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + ".png"; RenderTexture rt = new RenderTexture(resWidth, resHeight, 24); camera.targetTexture = rt; Texture2D screenShot = new Texture2D(resWidth, resHeight, TextureFormat.RGB24, false); Rect rec = new Rect(0, 0, screenShot.width, screenShot.height); camera.Render(); RenderTexture.active = rt; screenShot.ReadPixels(new Rect(0, 0, resWidth, resHeight), 0, 0); screenShot.Apply(); byte[] bytes = screenShot.EncodeToPNG(); File.WriteAllBytes(name, bytes); } } | cs |
GameObject파일을 만들어 스크립트를 넣어준후 원하는 카메라를 넣어준다.
그후 Button을 만들어 ScreenShot.cs안에있는 ClickScreenShot()이라는 함수를 넣어주면 끝!~
이렇게 버튼이 나오지 않고 카메라에 보이는것만 나옵니다.
'언어 > Unity' 카테고리의 다른 글
[Unity]List사용 (0) | 2018.01.24 |
---|---|
[Unity]대리자를 이용한 콜백함수 만들기 (958) | 2018.01.22 |
[Unity]대리자 delegate (20) | 2018.01.20 |
[Unity]Split함수로 문자열 자르기 (0) | 2018.01.19 |
[Unity]String to Int 파싱 (0) | 2018.01.17 |