Call JavaScript function from Unity and vice versa - JavaScript Unity Bridge

preview_player
Показать описание
UPDATE: many people says that they did not find the source code, here is again the source code in this link, direct link to my Google Drive:

When building a Unity program for web (WebGL), mostly we need to access methods/functions inside Unity from JavaScript (browser scripting).

This example is showing how it can be done. In this example I’m showing how to call JavaScript alert from Unity and then send back some string text to Unity Scene from web browser.

Рекомендации по теме
Комментарии
Автор

since there are not so many clear examples on youtube about webGL your knowledge is precious thanx for sharing this!!!

pabloownerofthebrokenh
Автор

legend, better explained than the unity documentation

svndays
Автор

Anyone facing problem of UI elements not taking inputs from browser, please make sure that your start function has WEBGl.captureAllkeyboardinput = false and then build the code.
So in short follow the video thoroughly.

bhupiistersingh
Автор

Thank you so much! this is very helpful!

bgxs
Автор

​ @ThirteeNov hi,
what i didn't understand was:
1. I've seen that you had in the project unityloader.js and UnityJS.json files in the folder.
which ones did you use?



2. the index.html i buit was very different than urs (lot more 'div's act) did you just add the scripts in the header and body in 2:36 or did you add/remove anything else?



and 3. in 0:36 it the video did not show how did you call the function from the page button.
from the HTML pages JS file that is.
In my case I don't run the unity project locally but via have a link from remote storage, open an Iframe and inject the content there.
It wasn't clear to me how will the window JS file use the functions of the index.http.

was my question more clear now? apologise for the confusion.

nirharpaz
Автор

perfect, great Tutorial, i followed all of your steps one by one, but still when i play the unity webgl on localhost, it gives me error that the method is null or mismatch, how to resolve this? im using unity 6

wasifalmeem
Автор

anybody get this error: DllNotFoundException: Unable to load DLL '__internal'. Tried the load the following dynamic libraries
I'm lost!!

hamidmactabi
Автор

i keep getting a System.EntryPointNotFoundException, how do i fix this

yours_indie_game_dev
Автор

If one "follows the video thoroughly" as a precedent comment said, only half of this demo will work : sending messages from JS to unity.
Sending messages from Unity to JS definitely cannot work, you do not show us the Button's mapping. So after replicating what we see in the video, the Unity button is not mapped.

To map the Unity button "Sent to JS", do the following :
Click on Button on the hierarchy left panel -> on the Inspector panel on the right, click the little "+" under the "On Click()" line -> Under "Runtime Only", select Bridge script -> Select Bridge.SendToJS method.


-Additionnally, correct me if I am wrong, you do not give sources files but only the built project. One can try the result at home by hosting a web server with your built files, but cannot modify it or understand it without sources.-

New Unity users may have a hard time, hope they will read this comment.

iceteapowatv
Автор

there is some option to be able to read a txt file, let's say I export the project, and to be able to add a /Data/user.txt and from js read what that file contains, I would appreciate your help

esrivera
Автор

can you show me as well how to do that in android build? i have "DllNotFoundException" error message. is it possible?

lohkan
Автор

Hello buddy, please l need your help l get the error DLL cannot found exception _Internal

armandocomellas
Автор

Hey! How to sync float range slider from js to to Unity? Thanks

nicolasportu
Автор

Thanks! But why do I get EntryPointNotFound exception?

sadiqabbaszade
Автор

Hi, I need to send a table from JS to Unity, any idea how I can do that?

glennanicoche
Автор

can i call javescript function in jslib file

Testvkre
Автор

But i am not able to get keyboard input after implementing this please help

rajat
Автор

Thank you! Is it also possible to send objects instead of pure text to js and vice versa? Can you show me how to do it?

joeyzhou
Автор

And for async js functions? how works? good video

rayoseldev