纳金网

标题: unity3d 网页(webplayer)取unity3d里的对象 [打印本页]

作者: yeu1233    时间: 2012-9-6 10:39
标题: unity3d 网页(webplayer)取unity3d里的对象

Calling Unity web player content functions from the web page
The Unity Web Player object has a function, SendMessage(), that can be called from a web page in order to call functions within Unity web player content. This function is very similar to the GameObject.SendMessage function in the Unity scripting API. When called from a web page you pass an object name, a function name and a single argument, and SendMessage() will call the given function in the given game object.
In order to call the Unity Web Player's SendMessage() function you must first get a reference to the Unity web player object. You can use the GetUnity() function in the default html generated by Unity to obtain a reference to the object. Here is an example JavaScript function that would***cute the SendMessage() function on the Unity web player; in turn SendMessage() will then call the function MyFunction() on the game object named MyObject, passing a piece of string data as an argument:


<script type="text/javascript" language="javascript"> <!-- function SaySomethingToUnity() {  var unity = GetUnity();  unity.SendMessage("MyObject", "MyFunction", "Hello from a web page!"); } --> </script>
Inside of the Unity web player content you need to have a script attached to the GameObject named MyObject, and that script needs to implement a function named MyFunction:


function MyFunction(param : String) {     Debug.Log(param); }





欢迎光临 纳金网 (http://wwww.narkii.com/club/) Powered by Discuz! X2.5