reactjs - 如何将 Unity WebGL 放入我的 React Native 应用程序中?

标签 reactjs unity-game-engine react-native unity-webgl

我使用 WebGL 编写了一个简单的 React Native 应用程序。 我用过https://github.com/JilvanPinheiro/reactive-native-unity-webgl

import Unity from 'react-native-unity-webgl';
...
render() {
  return (
 <Unity 
       width="500px"
       height="350px"
       onProgress={ this.onProgress }
       src="http://192.168.1.101/Build/Ultimatum.json" 
       loader="http://192.168.1.101/Build/UnityLoader.js" />`
  );
}

但我收到以下错误:

ReferenceError:  Can't find variable: document. This error is located at:
    in Unity (at App.js:9)
    in RCTView (at View.js:60)
    in View (at App.js:8)
    in App (at registerRootComponent.js:35)
    in RootErrorBoundary (at registerRootComponent.js:34)
    in ExpoRootComponent (at renderApplication.js:33)
    in RCTView (at View.js:60)
    in View (at AppContainer.js:102)
    in RCTView (at View.js:60)
    in View (at AppContainer.js:122)
    in AppContainer (at renderApplication.js:32)

是否有更简单的方法将 Unity webGL 放入我的 React Native 应用程序中?

最佳答案

你必须从 react-native 导入 React 和 document 试试这个,它会解决你的问题,并且确保你下载了与你的版本匹配的版本Unity版本

import React, {Component} from 'react';
import {View,document} from 'react-native';

关于reactjs - 如何将 Unity WebGL 放入我的 React Native 应用程序中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50819780/

相关文章:

javascript - 为什么 react 路由器抛出 'Cannot GET/example' 错误?

reactjs - Uncaught Error : Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object

javascript - react native : Error while downgrading from 0. 51 到 0.45

c# - 使用 HttpWebRequest 下载后 PNG 文件显示为红色问号

javascript - 如何将您的开发堆栈与您的项目分开?

c# - 玩家卡牌收集 MySQL

c# - Unity 内部编译器错误与自定义 dll

objective-c - react-native RCTBridgeModule 的初始化

css - Flexbox 将中心与右侧的另一个元素对齐

firebase - 此构建中使用了已弃用的 Gradle 功能,使其与 android studio 中的 Gradle 8.0 不兼容