你好,我正在尝试将 Unity WebGL 导出文件导入我的 React JS 项目中,但不知何故无法工作。我正在使用以下版本的React Unity WebGL(react-unity-webgl@7.x # For Unity 2018 and 2019 (Active LTS)),并且根据我正在使用的版本按照说明进行操作。有人遇到了和我一样的问题,并在GitHub上提出了一个问题,我按照他们说的做了,也就是把 unity 文件夹放在 public 文件夹里,但仍然无法正常工作。有人有任何想法如何解决这个问题吗?
这是我的文件夹结构:
以下是我尝试过的两种代码(它们基本相同):
代码 A:
import React from 'react'
import Unity, { UnityContent } from "react-unity-webgl";
let unityContent = new UnityContent(
"Megaman/Build/Megaman.json",
"Megaman/Build/UnityLoader.js"
);
function MegamanGame() {
return (
<div>
<h1>Is not working</h1>
<Unity unityContent={unityContent} />
</div>
)
}
export default MegamanGame
代码B:
import Unity, { UnityContent } from "react-unity-webgl";
export default function Megaman() {
let unityContent = new UnityContent(
"Megaman/Build/Megaman.json",
"Megaman/Build/UnityLoader.js"
);
return (
<div><Unity unityContent={unityContent} /></div>
);
}
以下是它的呈现方式
请注意,我已经尝试了两种路径:"Megaman/Build/Megaman.json"
或者只有 "/Build/Megaman.json"