I have written a simple React Native app using WebGL. I used 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" />`
);
}
But I'm getting the error below:
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)
Is there a simpler way to place Unity webGL in my React Native app?
Yes, We can integrate Unity in to React using Native Components for both iOS and Android.
Note that Unity WebGL content is not currently supported on mobile devices. It may still work, especially on high-end devices, but many current devices are not powerful enough and don't have enough memory to support Unity WebGL content well.
you must have to import React and document
from react-native
try this it will solve your problem and also Make sure you download the release matching with your Unity version.
import React, {Component} from 'react';
import {View,document} from 'react-native';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With