Hi, I have a unity web game which uses a external .js plugin which I source in the unity html …But facebook uses the .unity3d file directly and I am not able to source in the .js plugin or the html file…on the facebook developer page they say…
Injecting your own HTML/JS
Add a div element to the top of the iframe containing the game, which might contain a header for cross-promotion or related uses.
string injection =
“var headerElement = document.createElement(‘div’);” +
“headerElement.textContent = (‘Check out our other great games: …’);” +
“var body = document.getElementsByTagName(“body”);” +
"var insertionPoint = body.children; " +
…I dont know how to or where to put in the code to get it work…here is what i put in the unity html file to reference the .js plugin…
Can you tell me how we can achieve this…reference the html and js plugin ?
Please Help !
string injection = "var yourScript = document.createElement(\"script\");" +
"yourScript.src = \"//URLtoSource\"" +
For HTML this can be done the same way, but you need to select which tag add to in “var yourScript = document.createElement("script_-or-div-or-_header");” as well as the .type and where you append the code within the HTML body.
To execute this code, add this snippet to the appDelegate. Application.ExternalEval() will inject the code when the unity player loads and when the script is called. This can be done at the beginning (in appDelegate) or at a later time when it is needed. For my purposes, it was done at the very beginning because we have code that is dependent on this injection being completed before hand.
If the source code being injected is from an external source, I recommend conducting the injection as early as possible, because you will not know when the source injection has been completed. (Technically you can know when the source completes, but will take more setup by using callbacks from the webplayer. Research Unity Web Player and browser communication.)
EDIT: Additional information.