【发布时间】:2022-01-05 18:50:48
【问题描述】:
嘿,我试图让我的 Unity WebGL 导出在我的 React JS 项目上工作,但由于某种原因无法正常工作,我正在使用以下 React Unity WebGL 版本(react-unity-webgl@7.x # For Unity 2018 和2019 (Active LTS)) 并且我已经按照我正在使用的版本的说明进行操作,有人遇到了与我相同的问题并在GitHub 中提出了一个问题,我按照他们所说的基本上是把公用文件夹中的统一文件夹,但仍然无法正常工作。有人知道如何解决这个问题吗?
这就是我的文件夹结构:
这是我尝试过的两个代码(它们基本相同):
代码 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"
【问题讨论】:
-
您找到解决此问题的方法了吗?考虑self-answering 并在下面写下答案。
标签: reactjs react-native unity3d unity-webgl