As of 2020.1 there were changes, noted here:
https://discussions.unity.com/t/774226
If the library in question was created before 2020.1 (or only supports a version prior to that), it may require changes as well. SendMessage should still work though, as docs indicate it’s still supported as of latest listed version (2020.2). Example of use… create an element on the page like <div id="your_button_id">test</div>
, add this to jslib functions:
mergeInto(LibraryManager.library, {
InitializeTestButton: function(buttonId) {
var obj = document.getElementById(Pointer_stringify(buttonId));
obj.style.color = "blue"; // changes css text color of the element to blue just to see this function initialized it
obj.onclick = function() {
window.unityInstance.SendMessage("Javascript", "TestButtonClicked", "button clicked");
}
}
});
…then create an GameObject named “Javascript” (or whatever, but must match first param of SendMessage call) in the root of your scene and add a component:
using System.Runtime.InteropServices;
using UnityEngine;
public class Javascript : MonoBehaviour
{
[DllImport("__Internal")] public static extern void InitializeTestButton(string buttonId);
#if UNITY_WEBGL && !UNITY_EDITOR
void Start()
{
InitializeTestButton("your_button_id"); // the id="" value of the HTML element that you want to click
}
#endif
public void TestButtonClicked(string msg)
{
Debug.Log(msg); // javascript console should output "button clicked" when the element is clicked
}
}
Edit: I just realized I gave almost an exact same example as I did earlier in the thread, I should have read through this first and I’d have noticed it was actually the same thread