Unity combined with the web

Source: Internet
Author: User
Tags unity 5

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.