React unity WebGL 不适用于 React JS 项目

Rea*_*ato 5 unity-game-engine reactjs react-native unity-webgl

嘿,试图让我的 Unity WebGL 导出在我的 React JS 项目上工作,但由于某种原因不起作用,我正在使用以下React Unity WebGL版本(react-unity-webgl@7.x # For Unity 2018 和 2019(Active LTS)),我已经按照我使用的版本的说明进行操作,有人遇到了与我相同的问题,并在 GitHub 中提出了一个问题,按照他们所说的进行操作,基本上是将 unity 文件夹公开文件夹,但仍然无法正常工作。任何人都知道如何解决这个问题?

这就是我的文件夹结构:

在此输入图像描述

这是我尝试过的两个代码(它们基本上是相同的):

代码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
Run Code Online (Sandbox Code Playgroud)

代码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>
    );
}
Run Code Online (Sandbox Code Playgroud)

这就是它的渲染方式

在此输入图像描述

请记住,我已经以两种方式尝试了这条路径,"Megaman/Build/Megaman.json"或者只是"/Build/Megaman.json"

小智 4

任何人都在这里回答:https://github.com/jeffreylanters/react-unity-webgl/discussions/299

代码很好,只需要添加“/Megaman/Build/Megaman.json”和“/Megaman/Build/UnityLoader.js”。

请记住,从版本 7.x 到 8.x,“UnityContent”已被重新设计为“UnityContext”。