- Home /
Loading external variables via SendMessage into Unity WebPlayer
if (typeof unityObject != "undefined") { unityObject.embedUnity("unityPlayer", "WebPlayer.unity3d", 600, 450); SaySomethingToUnity(); }
Above is the autogenerated javascript calling a function linked below.
I am trying to pass a text string to unity webplayer using SendMessage - basically, the function SaySomethingToUnity() sends a message to Unity webplayer from javascript.
But.. The text doesn't load. I wonder why..
Is there a way to detect if the Unity webplayer content has finished downloading first before calling SaySomethingTOUnity()
?
Answer by Thelo · Feb 22, 2011 at 03:26 AM
The best way to do that is to have the Unity game use a webpage callback when it's loaded.
In Unity:
Application.ExternalCall("OnUnityReady")
In the webpage:
function OnUnityReady() { SaySomethingToUnity(...); }
That way, you can be sure that Unity is fully loaded and ready to accept your message.
Answer by DaveA · Jan 23, 2011 at 09:27 AM
Look for the GetUnity() function in the auto-gen html, use that to access the player.
Worst case, you can have your first scene send a message out to the HTML via Application.ExternalCall() to signal that it's been loaded.
So the reason why the message isn't being sent is because the content hasn't loaded before the message was sent?