using System.Collections; using System.Collections.Generic; using UnityEngine; public class CreatMapFromCamera : MonoBehaviour { // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Space)) { CameraCapture(Camera.main, "山地.png"); } } void CameraCapture(Camera m_Camera, string filename) { RenderTexture rt = new RenderTexture(Screen.width, Screen.height, 16); m_Camera.targetTexture = rt; m_Camera.Render(); RenderTexture.active = rt; Texture2D t = new Texture2D(Screen.width, Screen.height); t.ReadPixels(new Rect(0, 0, t.width, t.height), 0, 0); t.Apply(); string path = Application.streamingAssetsPath + "/" + filename; System.IO.File.WriteAllBytes(path, t.EncodeToJPG()); m_Camera.targetTexture = null; } }