Import Unity file in React project

Viewed 1764

I am having trouble loading a Unity file in my React project. I thought if I add the file in index.html I would be able to use UnityLoader anywhere in the project as shown below:

index.html

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Game</title>
  </head>
  <body>
    <div id="app">
    </div>
    <script src="UnityLoader.js"></script>
  </body>
</html>

Unity.js

class Unity extends Component {

    render() {
        return (
            <div id="unity">
                {UnityLoader.instantiate('unity', 'unity/index.html')}
            </div>
        );
    }
}

However, I get an error saying UnityLoader is undefined.

Do I need to use some sort of

import { UnityLoader } from 'UnityLoader' 

in Unity.js? The issue is that UnityLoader is an external JS file and does not export anything.

1 Answers
Related