1. How to take screenshots in Unity
1. Use CaptureScreenshot Api, this method can only capture the full screen, generally this method is rarely used.
Application.CaptureScreenshot("Screenshot.png", 0);
2. You can customize the scope of interception, but there is a disadvantage that it cannot intercept the screen at the specified level. (For example, if I only want to take a picture, and I don’t need to take a screenshot of the camera button and UI screen, I need to hide the UI interface before taking a screenshot). This method is too cumbersome and rarely used.
private Texture2D texture2D=null;
private Rect rect = new Rect(Screen.width * 0f, Screen.height * 0f, Screen.width * 1f, Screen.height * 1f);
private IEnumerator ScreenshotAsyn()
{
if (texture2D != null) Destroy(texture2D);
texture2D = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.RGB24, false);
texture2D.ReadPixels(rect, 0, 0);
texture2D.Apply();
}
3. Take a screenshot of the specified camera level. (This method is more commonly used)
using UnityEngine;
/// <summary>截屏功能</summary>
public class Screenshot
{
private s