Skip to content

Commit 64fdc9a

Browse files
Added UnityEvents
1 parent 2e21778 commit 64fdc9a

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,28 +86,28 @@ this.myCustomModule = { ... }
8686

8787
<br/><br/><br/>
8888
# Calling Unity scripts functions from JavaScript in React
89-
Sometimes you need to send some data or notification to the Unity script from the browser’s JavaScript. The recommended way of doing it is to call methods on GameObjects in your content. To get started import the function SendMessage from react-unity-webgl.
89+
Sometimes you need to send some data or notification to the Unity script from the browser’s JavaScript. The recommended way of doing it is to call methods on GameObjects in your content. To get started import the class UnityEvent from react-unity-webgl.
9090

9191
```js
92-
SendMessage (objectName: String, methodName: String, value: Object): void;
92+
UnityEvent (objectName: String, methodName: String);
9393
```
9494

95-
Where objectName is the name of an object in your scene; methodName is the name of a method in the script, currently attached to that object; value can be a string, a number, or can be empty. For example:
95+
Where objectName is the name of an object in your scene; methodName is the name of a method in the script, currently attached to that object. When you've created a new UnityEvent, you can call the 'emit' function to fire it into Unity. You can pass an optional parameter value.
9696
```js
9797
import React from 'react'
98-
import { SendMessage } from 'react-unity-webgl'
98+
import { UnityEvent } from 'react-unity-webgl'
9999

100100
export class App extends React.Component {
101-
spawnEnemy (count) {
102-
SendMessage ('SpawnBehaviour', 'SpawnEnemies', count)
101+
constructor () {
102+
this.spawnEnemies = new UnityEvent ('SpawnBehaviour', 'SpawnEnemies')
103103
}
104104
render () {
105-
return <div onClick={ this.spawnEnemy.bind(this, 5) }>
105+
return <div onClick={ this.spawnEnemies.emit (5) }>
106106
Click to Spawn 5 Enemies</div>
107107
}
108108
}
109109
```
110-
While in Unity, for example:
110+
While in Unity the following script is attached the a game object named 'SpawnBehaviour'.
111111
```cs
112112
using UnityEngine;
113113

0 commit comments

Comments
 (0)