Call JavaScript function from Unity and vice versa – Unity JavaScript Bridge

When building a Unity program for web (WebGL), mostly we need to access methods/functions inside Unity from JavaScript (browser scripting).

This example is showing how it can be done. In this example I’m showing how to call JavaScript alert from Unity and then send back some string text to Unity Scene from web browser.

Watch the video here:

And get all the files here: https://drive.google.com/open?id=1rWFj26l1P0ut9W6Kc0HU0GpJzW6DVxTJ

4 thoughts on “Call JavaScript function from Unity and vice versa – Unity JavaScript Bridge

  1. Make sure you have this javascript code at the bottom of your html:

    var recaptureInputAndFocus = function() {
    var canvas = document.getElementById(“#canvas”);
    if(canvas) {
    canvas.setAttribute(“tabindex”, “1”);
    canvas.focus();
    } else
    setTimeout(recaptureInputAndFocus, 100);
    }
    recaptureInputAndFocus();

Leave a Reply

Your email address will not be published. Required fields are marked *