You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Calling Unity scripts functions from JavaScript in React](#calling-unity-scripts-functions-from-javascript-in-react)
19
+
-[Calling JavaScript functions within React from Unity scripts](#calling-javascript-functions-within-react-from-unity-scripts)
20
+
-[Notes](#notes)
21
+
-[5.x to 6.x Upgrade note](#5x-to-6x-upgrade-note)
22
+
-[Contributing](#contributing)
23
+
6
24
7
25
8
26
9
27
10
28
# Installation
11
-
Install using npm. Make sure you download the release matching with your Unity version. I try to update this plugin in case of need as fast as possible. Check the [releases on GitHub](https://github.com/jeffreylanters/react-unity-webgl/releases) for the corresponding version.
29
+
Install using npm. Make sure you download the release matching with your Unity version. I try to update this plugin in case of need as fast as possible. Check the [releases on GitHub](https://github.com/jeffreylanters/react-unity-webgl/releases) for the corresponding version or [view on NPM](https://www.npmjs.com/package/react-unity-webgl).
12
30
13
31
```sh
14
-
$ npm install --save react-unity-webgl
32
+
$ npm install react-unity-webgl
15
33
```
16
34
17
35
18
36
19
37
20
38
21
39
# Usage
22
-
To get started import the default Unity class from react-unity-webgl.
40
+
To get started import the default Unity class from react-unity-webgl and include it in your render while giving the public path to your src and loader files.
23
41
24
42
```js
25
43
importReactfrom'react';
@@ -28,20 +46,22 @@ import Unity from 'react-unity-webgl';
28
46
exportclassAppextendsReact.Component {
29
47
render () {
30
48
return<Unity
31
-
src='Build/myGame.json'
32
-
loader='Build/UnityLoader.js'/>
49
+
src='Public/Build/myGame.json'
50
+
loader='Public/Build/UnityLoader.js'/>
33
51
}
34
52
}
35
53
```
36
54
## Optional attributes
37
55
38
-
### Overruling the module
56
+
### Width and height
57
+
The default width and height is 100%
39
58
```js
40
-
this.myCustomModule= { ...}
41
-
<Unity ...module={ this.myCustomModule }/>
59
+
<Unity ...width='500px' height='350px'/>
60
+
<Unity ...width='50%' height='50%'/>
42
61
```
43
62
44
63
### Tracking progression
64
+
The loading progression of the Unity player will be a value between 0 and 1
45
65
```js
46
66
<Unity ... onProgress={ this.onProgress } />
47
67
onProgress (progression) {
@@ -51,6 +71,13 @@ onProgress (progression) {
51
71
}
52
72
```
53
73
74
+
### Modules
75
+
Overrides the module object
76
+
```js
77
+
this.myCustomModule= { ... }
78
+
<Unity ...module={ this.myCustomModule } />
79
+
```
80
+
54
81
55
82
56
83
@@ -132,7 +159,7 @@ Legacy ways of calling JavaScript code from Unity. You can use the Application.E
132
159
133
160
134
161
# Notes
135
-
Make sure your Unity build is in your public folder, this is due to the component **and** Unity itself will load files in Runtime and not Compile time.
162
+
Make sure your Unity build is in your public folder, this is due to the component **and** Unity itself will load files in Runtime and not Compile/Bundle time.
136
163
## 5.x to 6.x Upgrade note
137
164
When upgrading from 5.x to 6.x, make sure you add the `loader` prop to the Unity component and remove the script tag from your HTML page refering to the UnityLoader.js file. See [Usage](#usage) for further details.
0 commit comments