Unity WebGL Metamask Connection - nethereumUnityInstance is not defined in javascript

597 Views Asked by At

I tried to connect Metamask wallet to Unity WebGL. Here is the github sample project link that I refered.

https://github.com/Nethereum/Nethereum.Unity.Webgl

I installed the same version of Unity to let the sample project work properly.

  • Unity Version : 2021.2.13f1
  • Microsoft Visual Studio : 2022

I built and run the project.

This is the build settings window

After running, there was not any problem.

I click the [Connect] button

And the Metamask extension window popped up as like other Metamask wallet connections

After connect to the Metamask I continuously got this error.

This is the image of the error

This is the image of browser javascript console error

This is the place in build folder where the error is originally occured

I do not know why this happeneds. I manually followed the sample project.

I have to connect Metamask to Unity WebGL. And I have to run a transaction via an account that is connected to Unity WebGL.

Could anybody help me? Could anybody give me alternative option to connect and run a transaction ?

1

There are 1 best solutions below

0
On

You have to edit the index.html to add nethereumUnityInstance = unityInstance;

createUnityInstance(canvas, config, (progress) => {
    progressBarFull.style.width = 100 * progress + "%";
}).then((unityInstance) => {
  nethereumUnityInstance = unityInstance;
  loadingBar.style.display = "none";
  fullscreenButton.onclick = () => {
    unityInstance.SetFullscreen(1);
  };
})

There is a github issue about it here: GitHub Nethereum #5