Search Unity

Question : WEBGL calling external js function

Discussion in 'Unity 5 Pre-order Beta' started by peter_on, Oct 27, 2014.

  1. peter_on

    peter_on

    Joined:
    Jan 8, 2009
    Posts:
    63
    hi,

    Looking for examples to call external js function from webgl exports.

    Br,
    peter
     
  2. sluice

    sluice

    Joined:
    Jan 31, 2014
    Posts:
    416
    It's probably the same as it was for WebPlayer:

    Code (csharp):
    1. Application.ExternalCall("MyJavascriptFunctionName", "Hello Javascript function!");
     
  3. RalphH

    RalphH

    Unity Technologies

    Joined:
    Dec 22, 2011
    Posts:
    591
    @sluice his answer is correct, and the easiest way to invoke Javascript.

    However, there are other, currently not well documented ways of doing things that allow you to have fast and integrated js interaction while providing C# wrappers for JS yourself; while for more complex C# types you'll have to do the marshalling yourself (unlike p/invokes), it allows you to provide a jslib file (which isn't much more then an emscripten module), and then through [DllImport("__Internal")], create C# bindings to call into it.

    We'll provide examples soon.
     
    codestage likes this.
  4. sluice

    sluice

    Joined:
    Jan 31, 2014
    Posts:
    416
    @RalphH
    Nice, looking forward to this!
     
  5. peter_on

    peter_on

    Joined:
    Jan 8, 2009
    Posts:
    63
    Can't wait to try it out!
     
  6. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,633
    Actually check the Unity 5.0 manual, it does contain a sample on how to do this.
     
  7. MvanDoorn

    MvanDoorn

    Joined:
    Nov 28, 2013
    Posts:
    1
    Where can I find the Unity 5.0 Beta manual / documentation?
     
  8. Jago

    Jago

    Joined:
    Aug 28, 2009
    Posts:
    30
    I think it's not online yet, but is installed locally on your system with the beta.
     
  9. sluice

    sluice

    Joined:
    Jan 31, 2014
    Posts:
    416
    @MvanDoorn, @Jago,

    In Unity, see

    Help / Unity Manual
    Help / Scripting Reference
     
unityunity