我有困难在我的React项目中加载Unity文件。我认为如果我将文件添加到index.html中,我就可以像下面展示的那样在项目中的任何地方使用UnityLoader:
index.html
然而,我收到了一个错误提示,说“
我需要使用某种...(后面的内容没有完整提供,无法翻译)
在Unity.js中?问题在于UnityLoader是一个外部JS文件,不导出任何内容。
index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Game</title>
</head>
<body>
<div id="app">
</div>
<script src="UnityLoader.js"></script>
</body>
</html>
Unity.js
class Unity extends Component {
render() {
return (
<div id="unity">
{UnityLoader.instantiate('unity', 'unity/index.html')}
</div>
);
}
}
然而,我收到了一个错误提示,说“
UnityLoader
未定义”。我需要使用某种...(后面的内容没有完整提供,无法翻译)
import { UnityLoader } from 'UnityLoader'
在Unity.js中?问题在于UnityLoader是一个外部JS文件,不导出任何内容。
<script src="relativePathToUnityLoader></script>
添加到public/index.html中。但也许这是错误的文件?因为它仍然显示:React-Unity-Webgl error:The UnityLoader was not defined...
。我还尝试在.js文件中进行常规的import "relativePathToUnityLoader";
。这反而给我带来了'webAssembly' is not defined, unexpected use of screen
等问题。 - Aidin