查看: 1940|回复: 0
打印 上一主题 下一主题

unity3d 网页(webplayer)取unity3d里的对象

[复制链接]

435

主题

2

听众

6371

积分

高级设计师

Rank: 6Rank: 6

纳金币
6372
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2012-9-6 10:39:20 |只看该作者 |倒序浏览

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); }
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

关闭

站长推荐上一条 /1 下一条

手机版|纳金网 ( 闽ICP备08008928号

GMT+8, 2024-5-22 08:47 , Processed in 0.084430 second(s), 33 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部