I have a WebGL unity project which attempts to execute javascript code on the browser and return a value.
I have the following .jslib
file in my Assets/Plugins/WebGL folder:
var BrowserPlugin = {
GetEndpointURL: function()
{
var endpoint = window.itd.getEndpointUrl();
console.log("endpoint: " + endpoint);
return endpoint;
}
};
mergeInto(LibraryManager.library, BrowserPlugin);
In my c# code in unity, I import the dll and call my javascript method like so:
[DllImport("__Internal")]
private static extern string GetEndpointURL();
string endpointURL = GetEndpointURL();
The problem is, in my c# code the endpointUrl
variable is always null. However, in my browser console, I can clearly see the correct value is logged in the browser javascript before I return it. What is causing this value to come back to unity as null?