[英]React unity WebGL not working on React JS project
嘿那里試圖讓我的 Unity WebGL 導出在我的 React JS 項目上工作,但由於某種原因無法正常工作我正在使用以下React Unity WebGL版本(react-unity-webgl@7.x # For Unity 2018 和 2019(活動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"
任何人都在這里回答: https://github.com/jeffreylanters/react-unity-webgl/discussions/299
代碼很好,只需要添加“/Megaman/Build/Megaman.json”和“/Megaman/Build/UnityLoader.js”。
請記住,“UnityContent”已從 7.x 版本改寫為“UnityContext”到 8.x 版本。
你必須將你的 unitybuid 文件夾作為公共文件的子文件夾,因為這個 /public/Build/yourfiles.json
之后我遇到了問題,它在本地主機上運行良好,但是在托管站點上構建時,它不會為我加載。
我有同樣的問題。 我正在開發 Unity 2019.4 並構建 Webgl 以在 React 中運行,但是當我使用 react-unity-webgl 時:
const GameMeta = () => {
const unity = new UnityContent({
loaderUrl: "game/Build/UnityLoader.js",
dataUrl: "game/Build/Meta-0.0.1.data.unityweb",
frameworkUrl: "game/Build/Meta-0.0.1.wasm.framework.unityweb",
codeUrl: "game/Build/Meta-0.0.1.wasm.code.unityweb",
});
);
return <div>
<h1>Hello game</h1>
<Unity UnityContent={unity} />
</div>;
}
我也收到錯誤“TypeError:無法讀取未定義的屬性(正在讀取'setComponentInstance')”任何人都可以幫助我們@@
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.