Reputation: 3697
I want to implement WebGL model viewer using Unity. This viewer is integrated into existing website. On this website there is a list of models and when user clicks on a model a window pops out displaying this model (like sketchfab). I integrate model viewer which was built with Unity WebGL using
<iframe src="./path-to-unity-webgl-viewer"></iframe>
How can I communicate with the viewer. Is there a way to create some javascript API using Unity which can be accessed from outside Unity app?
Upvotes: 0
Views: 1750
Reputation: 2579
Yes! See: https://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html
I did this for my games site, https://simmer.io by using SendMessage and JSLib as described in that article. Once you have that communication going, you need to do an additional layer of cross frame communication.
If this is on the same domain as you, it's easy (Communication between iFrames?). If the frames are on separate domains, you use cross domain messaging. See: http://blog.teamtreehouse.com/cross-domain-messaging-with-postmessage
Upvotes: 1