- Home /
Application.ExternalCall Issue
Hey folks, I've just got started a project which is using a combination of the Unity WebPlayer and a js framework for the UI, but I'm facing a problem trying to make the WebPlayer call a js function in my web page. I know that the way to achieve it is to call the Application.ExternalCall function from Unity, but for some unknown reason it doesn't seems to work for me, while I have no problems calling a Unity function from the webpage calling the getUnity().SendMessage method.
Basically, what I'm trying to do is to get reference to all the lights in the scene, create a List of serializable classes with just some basic informations, serialize a JSON string from the list and finally pass the resulting json to the javascript function in my page. Here's the script attached to an empty game object in the scene:
 public class Environment : MonoBehaviour {
             
     void Start () {
         Light[] Lights = FindObjectsOfType(typeof(Light)) as Light[];
         List<LightModel> LightRecords = new List<LightModel>();
                 
         foreach (Light light in Lights) {
             LightModel record = new LightModel();
             record.name = light.name;
             record.intensity = light.light.intensity;
             
             LightRecords.Add(record);
         }
                 
         string json = JsonConvert.SerializeObject(LightRecords);
         Application.ExternalCall("loadStore", json);
         Debug.Log(json);
     }
         
 }
and this is the javascript function in my webpage:
 <script type="text/javascript" language="javascript">
     <!--
     function loadStore( arg )
     {
         // show the message
         alert( arg );
     }
     -->
 </script>
     
For some reason, the alert is never shown..
You can notice a Debug.log at the end of the Unity Script. Trying to run the scene from unity the json is logged correctly so everything works there
 [{"name":"myLight","intensity":1.0},{"name":"dayLight","intensity":0.5}]
Can you guys shed some light here on what I'm doing wrong? Any help will be highly appreciated!
Thanks
Your answer
 
 
             Follow this Question
Related Questions
Developing a game for webplayer. Do I need to use javascript? 1 Answer
Multiple Cars not working 1 Answer
TypeLoadException: Could not load type '' from assembly 'Assembly-UnityScript'. 0 Answers
Distribute terrain in zones 3 Answers
getUnity function not returning unity object in Web Player 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                