WebGL: Interacting with browser scripting unable to call java script method from C#

Hello,

I want to to interact with javascript from c#. For this I was following the below link:

When I am trying to call any method from c# it gives me error missing function.

For eg: I have created a method in javascript like this.

mergeInto(LibraryManager.library, {
Hello: function () {
window.alert(“Hello, world!”);
},
});

and placed this script at path Assets/Plugins/WebGL/MyPlugin.jslib.

Then I am trying to access this method from c# like:

using UnityEngine;
using System.Runtime.InteropServices;

public class NewBehaviourScript : MonoBehaviour {

[DllImport("__Internal")]
private static extern void Hello();

void Start() {
    Hello();
}

}

but it gives me
missing function : Hello
while running it on browser. Please screen shot for the same

Please Help me out! Thank you!

HI, @unity_mwF5s3xOpUdXNA.
I checked your code on my computer. Everything works perfectly!
Perhaps you made a mistake elsewhere 114196-screenshot-1.png

My Code in C#

using System.Runtime.InteropServices;
using UnityEngine;

public class TestBrowser : MonoBehaviour {

[DllImport("__Internal")]
private static extern void Hello();

void Start()
{
     Hello();
}

}

jslib:

mergeInto(LibraryManager.library, {

Hello: function () {
window.alert(“Hello, world!”);
},

});

Location jslib: Assets/Plugins/WebGL/MyPlugin.jslib

My reply over here is very late entry considering the question has been asked over a ago. So I faced a similar problem.

Your javascript and C# code seems fine which means the problem lies somewhere else. In my case I had forgot to change the .jslib plugin platforms from Unity’s inspector window. When I was receiving missing function error, my .jslib plugin was checked into Editor platform. I unchecked it and checked WebGL platform. After creating the build everything worked as it was supposed to be.

I’m attaching a screenshot so you or anyone else facing a similar problem can understand.