网页js传值给unity3d

Unity3D发布成web形式后,可以通过 GetUnity().SendMessage("gameobj","function_name",value); 给u3d传递参数。不过,要注意的是在web中要等u3d加载完传值才能成功,所以要通过以下js程序以2秒时间循判断GetUnity()是否为空。

   1:  <script defer="defer">
   2:  var action= window.setInterval( "set_p()",2000); 
   3:  function set_p() 
   4:  { 
   5:  if( GetUnity() == null) 
   6:  { 
   7:  return; 
   8:  } 
   9:  else 
  10:  { 
  11:  var id= document.getElementById("id").innerHTML;  
  12:  GetUnity().SendMessage("Cam","get_id",id);  
  13:  window.clearInterval(action); 
  14:  } 
  15:  } 
  16:  </script>
  17:  <style type="text/css">

posted on 2012-12-04 07:46  tokutoku  阅读(554)  评论(0编辑  收藏  举报

导航