Quantcast
Channel: Questions in topic: "unitywebplayer"
Viewing all articles
Browse latest Browse all 452

Capture Screenshot not working in WebGL

$
0
0
I tried making a script that uses the main camera to take a screenshot of the object. It works well in unity without any errors but I tried to build it as a WebGL. Sadly, it shows an error that tells me to enable the exception to know it. Enabled it and didn't figure out anything at all. Is there something I missed with the WebGL coding? Any help would be appreciated. Thank you! using UnityEngine; using System.Collections; public class ScreenCapture : MonoBehaviour { public int resWidth = 960; public int resHeight = 600; public static string ScreenShotName(int width, int height) { return string.Format("C:/PerfLogs/screen_{1}x{2}_{3}.png", Application.dataPath, width, height, System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")); } public void ScreenshotButton() { RenderTexture rt = new RenderTexture(resWidth, resHeight, 24); GetComponent().targetTexture = rt; Texture2D screenShot = new Texture2D(resWidth, resHeight, TextureFormat.ARGB32, false); GetComponent().Render(); RenderTexture.active = rt; screenShot.ReadPixels(new Rect(0, 0, resWidth, resHeight), 0, 0); GetComponent().targetTexture = null; RenderTexture.active = null; // JC: added to avoid errors Destroy(rt); byte[] bytes = screenShot.EncodeToPNG(); string filename = ScreenShotName(resWidth, resHeight); System.IO.File.WriteAllBytes(filename, bytes); Debug.Log(string.Format("Took screenshot to: {0}", filename)); Debug.Log("Screenshot Saved!"); } } Here's a picture of the error. ![alt text][1] [1]: /storage/temp/81763-asd.jpg

Viewing all articles
Browse latest Browse all 452

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>