Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I place Unity WebGL in my React Native app?

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?

like image 314
Danil Chernokalov Avatar asked Jun 12 '18 14:06

Danil Chernokalov


People also ask

Can I use Unity with react native?

Yes, We can integrate Unity in to React using Native Components for both iOS and Android.

Can Unity WebGL run on mobile?

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.


1 Answers

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';
like image 100
manan5439 Avatar answered Oct 04 '22 00:10

manan5439