Is it possible to control the scene in the Unity3D Plugin by using JavaScript? The JavaScript-Code should run in the context of the browser and not in the context of the Unity3D Plugin?
I have to transform, delete and add objects in the scene.
Perhaps do you have an example.
Thanks for any advice.
Yes, it’s possible – at least, I know I’ve done it, but it was quite some time ago.
Here’s the demo page I put together back then.
Feel free to look in the page’s source code. Most of it comes from Unity’s docs and examples. I just made a simple wrapper for the sending and receiving of messages to/from the Unity web player, and adapted the code a little.
My code is based on Prototype.js, so you’ll have to do some minor rewrites if you’re using jQuery (like most people these days), but it shouldn’t be too bad. Or you can just use Unity’s pre-made stuff.
I’m not usually a Unity coder so I can’t tell you exactly how to set up the Unity-side of things (I did make the simple shader-based demo you see, but I’ve lost the source files, I think), but as I recall, it was simply a matter of creating a game object with a set of public methods. Those methods can then be called via JavaScript. Simple as that.
Basically, from the JS-side, all you have to do is this:
You can also send messages from the a GameObject back to JavaScript, if you want. It doesn’t happen in the demo, but it should work. Check the source for details.