Search code examples
javascripthtmlunity-game-engineunity-webgl

Send string to UnityWebGL jslib


I tried using jslib to show alert message , but the alert windows show strange numbers for me.

like 48616488 58926312 20535112 21654936 25634800

But I send same string , what I get this numbers?

This is code:

jslib

  IAUDIO: function (str) {
            alert(str);
  }

c#

    [DllImport("__Internal")]
    public static extern void IAUDIO(string s);

    void SendData(){
    IAUDIO("Test");
    }

Solution

  • Just like your last question. You can't use string sent from C# directly. The string is passed as a pointer and you need a way to access it from the memory. The Pointer_stringify function is used for this.

    IAUDIO: function (str) 
    {
        alert(Pointer_stringify(str));
    },
    

    Your C# code looks fine.