我使用 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/