還有其他方法可以截屏。沒有在WebGL上測試過,但你應該嘗試一下。
void CaptureScreenshot()
{
StartCoroutine(CaptureScreenshotCRT());
}
IEnumerator CaptureScreenshotCRT()
{
yield return new WaitForEndOfFrame();
string path = Application.persistentDataPath + "/Screenshot" + Time.frameCount + ".png";
Texture2D screenImage = new Texture2D(Screen.width, Screen.height);
//Get Image from screen
screenImage.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
screenImage.Apply();
//Convert to png
byte[] imageBytes = screenImage.EncodeToPNG();
//Save image to file
System.IO.File.WriteAllBytes(path, imageBytes);
}
此解決方案不會在我的應用程序中保存任何屏幕截圖。 – MaryLu
它現在可以在Unity中使用,但仍然不能作爲webGL導出:/ – MaryLu
@MaryLu首先,你說甚至沒有提供更多信息,甚至不保存任何屏幕截圖,現在你說它在Unity中工作,但不在WebGL中。我忽略這些評論。 – Programmer