

Public class BridgeScript : MonoBehaviour / Bridge used to communicate with a page Of course, we will need a script for it with the method we’ve provided on the page. We have to create one in the scene, I’ll call it “” like in code. We are still missing the receiver of that message! UnityInstance.SendMessage("", "ReceiveMessageFromPage", message) Īwesome! But this won’t work yet. Params: "Target object in the scene", "Function name", "Parameters" Function which sends the message to UnityĬonst txtMessage = document.getElementById("txtMessage") With form ready, now we need a function to go with it. We will have to create a panel or form on our page to enter the message which will be passed to Unity. The second part is a little bit harder to do. Function which receives a message from UnityĬonst lblMessage = document.getElementById("lblMessage") We also need to create a method on our page to receive the message and do something with it!
#Rush team web gl code#
However, the code in the plugin will not be enough for us here. ReceiveMessageFromUnity(convertedText) // This function is embeded into the page Var convertedText = Pointer_stringify(text) Method used to send a message to the page

Public static extern void SendMessageToPage(string text) / Class with a JS Plugin functions for WebGL. In our case, we will have just one method in it. It will serve the purpose of sending a message from Unity to the page. The first step to creating communication between Unity WebGL and the page will be to create a JS plugin. Now we have to follow new rules for interacting with browser scripting. In the old times you could call JS functions in WebGL directly from C# using Application.ExternalCall(), but we can’t do it any longer. To start, we need two things – a JS plugin and a receiver (bridge) in Unity.
