Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Ciix · Feb 18, 2015 at 08:37 AM · playerwebbrowsercommunication

Can't get SendMessage in webpage to send info to the web player

Can't get SendMessage in webpage to send info to the web player

I am trying to get the containing webpage to send information to the unity web player with no luck.

I followed what they have here: http://docs.unity3d.com/Manual/UnityWebPlayerandbrowsercommunication.html

But I read other comments on this and found that people advise making a call to a function on the containing webpage from the web player through the start function, to make sure it's loaded. Then I have that function execute SendMessage to send a text string back to the web player.

In the function (MyFunction) in Unity I just have it set a String variable to the text that is sent by SendMessage, then in OnGUI, I want it to display that value in a box, but I'm not able to get the value from SendMessage and assign it to the variable in my unity script.

Here is what I have:

In Unity:

myObjectScript.js ( this is attached to an object named MyObject)

 #pragma strict
 
 var myMessage : String = "testing..";
 
 function Start ()
 {
     Application.ExternalCall("DoSomething");
 }
 
 function OnGUI ()
 {
     GUILayout.Box("myMessage: " + myMessage);
 }
 
 
 function MyFunction(param : String)
 {
     myMessage = param;
 }


In the html file: (See the function DoSomething at the bottom. The rest is copied from the code generated by unity for the html file.)

 var config = {
     width: 960, 
     height: 600,
     params: { enableDebugging:"1" }
                 
     };
     var u = new UnityObject2(config);
 
 jQuery(function() {
 
     var $missingScreen = jQuery("#unityPlayer").find(".missing");
     var $brokenScreen = jQuery("#unityPlayer").find(".broken");
     $missingScreen.hide();
     $brokenScreen.hide();
                 
     u.observeProgress(function (progress) {
         switch(progress.pluginStatus) {
             case "broken":
                 $brokenScreen.find("a").click(function (e) {
                     e.stopPropagation();
                     e.preventDefault();
                     u.installPlugin();
                     return false;
                 });
                 $brokenScreen.show();
             break;
             case "missing":
                 $missingScreen.find("a").click(function (e) {
                     e.stopPropagation();
                     e.preventDefault();
                     u.installPlugin();
                     return false;
                 });
                 $missingScreen.show();
             break;
             case "installed":
                 $missingScreen.remove();
             break;
             case "first":
             break;
         }
     });
     u.initPlugin(jQuery("#unityPlayer")[0], "webcomm.unity3d");
     function DoSomething()
     {
              u.getUnity().SendMessage("MyObject", "MyFunction", "Hello!");
     }
 });

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jenci1990 · Feb 18, 2015 at 10:03 AM 0
Share

Application.ExternalCall("DoSomething()");

avatar image Ciix · Feb 18, 2015 at 08:34 PM 0
Share

I tried adding the (), but that didn't work. Also, in the manual they just have it in there without the (). I looked in my web console and it is saying "ReferenceError: DoSomething is not defined". Is there somewhere else where this needs to be defined?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Ciix · Feb 18, 2015 at 09:33 PM

Ok I got it now. I had to move DoSomething() outside of jQuery(function() {

....

});

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Change Web Player Size? 1 Answer

Web Player Auto Update Failed 8 Answers

unity web player has stopped responding 0 Answers

Failed to Update Unity Web Player on multiple browsers 0 Answers

Regarding PlayerPrefs vrs. (WebPlayer && Standalone) Builds 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges