Possible to take a screenshot? #232
Answered
by
jeffreylanters
oulfik
asked this question in
Question and Answer
-
Is it possible to take a screenshot with react-unity-webgl or do I have to call the unity function ScreenCapture.CaptureScreenshot() for this purpose? |
Beta Was this translation helpful? Give feedback.
Answered by
jeffreylanters
Sep 7, 2021
Replies: 1 comment 4 replies
-
Hi, ScreenCapture.CaptureScreenshot is not available is WebGL. I will add support for taking screenshots in the near future. But for now, there is an easy solution for taking screenshots from your web application as following: import React, { useEffect, useState } from "react";
import Unity, { UnityContext } from "react-unity-webgl";
const unityContext = new UnityContext({
loaderUrl: "build/myunityapp.loader.js",
dataUrl: "build/myunityapp.data",
frameworkUrl: "build/myunityapp.framework.js",
codeUrl: "build/myunityapp.wasm",
});
function App() {
const [canvas, setCanvas] = useState(null);
useEffect(function () {
unityContext.on("canvas", setCanvas);
}, []);
function takeScreenshot () {
const screenshotBase64 = canvas.toDataURL();
// Do something with the screenshot data...
}
return (
<div>
<button onClick={takeScreenshot}>Take Screenshot</button>
<Unity unityContext={unityContext} />
</div>
);
} |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
jeffreylanters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, ScreenCapture.CaptureScreenshot is not available is WebGL. I will add support for taking screenshots in the near future. But for now, there is an easy solution for taking screenshots from your web application as following: