Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

WebGL: Interacting with browser scripting

Discussion in 'Editor & General Support' started by bod, Jun 27, 2015.

  1. bod

    bod

    Joined:
    Jul 31, 2014
    Posts:
    17
    I am trying to access an external API via JavaScript from a WebGL build. I checked this page in the manual on how to access browser scripts from the index page.

    http://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html

    The SendMesage function seem to be exactly what I am looking for

    SendMessage ('MyGameObject', 'MyFunction', 'foobar');

    This how ever did not work so I checked the manual again and it stated this works the same as in the web player so I clicked the link for that

    http://docs.unity3d.com/Manual/UnityWebPlayerandbrowsercommunication.html

    But it has this Javascript code:

    <script type="text/javascript" language="javascript">
    <!-- //initializing the WebPlayer
    var u = new UnityObject2();
    u.initPlugin(jQuery("#unityPlayer")[0], "Example.unity3d");
    function SaySomethingToUnity()
    {
    u.getUnity().SendMessage("MyObject", "MyFunction", "Hello from a web page!");
    } --> </script>

    How would I modify this to get it to work with WebGL? It looks like you need a .unity3d file which is not part of the WSebGL build.

    any thoughts on this?
     
    Last edited: Jun 27, 2015