I need to include an external library (js) file in in my unity javascript bridge (jslib) for additional functionalities.
is this possible?
according to this: Unity - Manual: WebGL: Interacting with browser scripting
we can invoke the default javascript engine in unity, but im not sure if the including or importing an external javascript file is allowed.
The documetnation you linked is outdated.
Here’s more recent one:
Basically, if I remember correctly, the jslib function can call whatever. And if you’re running WebGL, in a browser, you can modify the webgl template and include additional scripts, if you’re so inclined.
No what i meant was, supposedly i have a file called mylibrary.js, that contains a single function called logme() that only log to a console, using the browser scripting mentioned in the links, is it possible to “include” or import that file in jslib and call logme() or do i need to do add the script tag and include mylibrary.js in the generated HTML after build for it to be visible?
Why not just test it?
In your scenario, I’d go with a script tag, and would use a *.jslib with a “forwarder” function that calls your library.
Hey, sorry I may be too late to the party here…
This is how I added an external js script to my page from inside a jslib
GetExternalJS: function() {
var script = document.createElement("script");
script.src = "https://scriptURLhere";
document.head.appendChild(script);
}
then on a gameobject in my first scene on Awake() I called that function to import it
I have a module that I need to import from within my project, but I’m not sure how to reference its path within the jslib file.
There are two things that I can’t figure out. First, where in my Unity project can I place the module where I can reference it from the jslib file. Second, the documentation for the module says to import a folder with several items and other folders within it, instead of importing a single script.
Your answer looks like it’s supposed to point towards a single file, but I’m pretty inexperienced with the web development/javascript side of things, so correct me if I’m wrong.
I’ve also tried adding another script reference manually into the index.html file, in which I try to import the 3rd party module exactly as they say to in their documentation, but I always end up getting an error message that says “Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of “text/html”. Strict MIME type checking is enforced for module scripts per HTML spec.”
I would be very grateful for any assistance in getting this to load properly.