unityContext.unityInstance always undefined #186
Unanswered
ZHSC17
asked this question in
Help Wanted!
Replies: 1 comment 6 replies
-
Hi. The Unity Instance is declared private and is only used internally. You should use the Unity Context's Send method instead. import React 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 spawnEnemies(amount) {
unityContext.send("GameController", "SpawnEnemies", amount);
}
const App = () => {
return (
<div>
<button onClick={() => spawnEnemies(100)}>Spawn!</button>
<Unity unityContext={unityContext} />
</div>
);
}; |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
After I initialize unitycontext, the Unity screen is loaded successfully, but I can't send messages,because unityContext.unityInstance always undefined.
this.unityContext.on('loaded',()=>{
this.unityContext.unityInstance.SendMessage("NewGameObject" , "TestMethod");
this.unityContext.send("NewGameObject" , "TestMethod");
})
Beta Was this translation helpful? Give feedback.
All reactions