Occasionally in the forum to see an article, feel very interesting, reproduced, before doing the game, now do the front end, this article is good. Reproduced
Unity Webplayer
write in front
Recently, in a project to communicate between unity and the web, we searched the Internet for some information
Often scattered is also some of the older version, even the official document has been given
Some of the error, which also stems from the update of the Web platform is too fast, at the same time unity has to constantly update the relevant documents. I'm using the Unity 5.2.2f Pro version, and I've been trying to figure out how to interact with the web in the most recent time and try to sort through the following:
embed Unity content in HTML
The content in unity is displayed in the browser via the Webplayer plug-in, and HTML is unityobject.js with the Webplayer session through the script.
Unityobject2.js can be a file in a server folder, or it can be a link on the official Unity website, the advantage of using the link is that you can keep the latest version of the Unityobject2.js file, and there may be some changes in function names and parameters causing the load to crash.
Determine if the network transport protocol is a secure channel through Document.location.protocol, and if it is an HTTPS secure channel, rewrite the resource reference URL in HTML to be a secure HTTP channel
<Scripttype= "Text/javascript"> <!-- varUnityobjecturl="Http://webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/UnityObject2.js"; if(Document.location.protocol== 'https:') Unityobjecturl=Unityobjecturl.replace ("/ http", "https://ssl-");d Ocument.write ('<script type= "Text/javascript" src= "' +Unityobjecturl+ '"></script>'); - </Script>
Instantiate the Unityobject2.js script, the first parameter of the Initplugin method is based on the first child node in the HTML tag with ID Unityplayer, and the second parameter is the Unity3d file generated after the bundle.
var New UnityObject2 (); U.initplugin (JQuery ("#unityPlayer" [0], "Example.unity3d");
This section of HTML is placed in the body tag:
<DivID= "Unityplayer"> <Divclass= "Missing"> <ahref= "http://unity3d.com/webplayer/"title= "Unity Web Player." Install now! "> <imgalt= "Unity Web Player." Install now! "src= "Http://webplayer.unity3d.com/installation/getunity.png"width= "193"Height= "The " /> </a> </Div></Div>
Unity combined with the web