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 imagoculturae · Feb 26, 2015 at 11:19 PM · webplayercommunication

Calling function with integer webpage communication

I am doing this in my webpage containing the player:

 function SaySomethingToUnity(var objindex){
 u.getUnity().SendMessage("ObjectManager", "MyFunction", objindex);
 }

and this:

 <button type="button" onclick="SaySomethingToUnity(1)">Click Me!</button>

then in Unity

 private var focusobject:int;
 
 function MyFunction(param: int){
 
 focusobject=param;
 FocusOnObjects();
 }
 
 function FocusOnObjects () {
 ...
 var bounds = new Bounds(GameObjects[focusobject].transform.position, Vector3.zero);
 ...        
 }

This is in order to pass a value depending on which object I am going to focus on when I click a web button.

The player does not load, if I use the original form from the documentation everything is fine, can anyone tell me why? Many thanks Nic

Comment
Add comment · Show 4
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 spiceboy9994 · Feb 27, 2015 at 12:00 AM 0
Share

If the player does not load it may be related to the html that you're changing on the form. Is It possible that you could check the dev tools on your browser so you can get the specific error?. Otherwhise, attach the html so I can let you know what the issue is

avatar image imagoculturae · Feb 27, 2015 at 12:40 AM 0
Share

firefox is saying this: SyntaxError: missing formal parameter WebDeployment.html:70:31 TypeError: new_document_root is undefined

With this works fine:

  function SaySomethingToUnity(){
  u.getUnity().Send$$anonymous$$essage("Object$$anonymous$$anager", "$$anonymous$$yFunction", "text");
  }

I don't get it because I thought that this function should only work when I call it with the button, what does it have to do with the webplayer not displaying?

avatar image imagoculturae · Feb 27, 2015 at 12:47 AM 0
Share

Ok, I deleted the argument and it works, but now how can I pass it to unity?

 function SaySomethingToUnity(?????){
   u.getUnity().Send$$anonymous$$essage("Object$$anonymous$$anager", "$$anonymous$$yFunction", objindex);
   }

avatar image imagoculturae · Feb 27, 2015 at 12:06 PM 0
Share

I found the solution but don't really know why...just used this ins$$anonymous$$d:

 ...
 var objindex;
 ...
 function SaySomethingToUnity(objindex){
    u.getUnity().Send$$anonymous$$essage("Object$$anonymous$$anager", "$$anonymous$$yFunction", objindex);
    }


I think this is a very good way of passing variables as arguments from the web to unity, so for example I can have a list of links which each one calling the same function but passing different arguments. Great I was trying to do this since awhile!

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by imagoculturae · Feb 28, 2015 at 01:26 PM

Not sure if this is the right way to do it but it has been solved by creating a variable at the top of the java script in the webpage and passing that variable as argument in the 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

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

WebPlayer TCPClient connect C# TCPServer app in localhost, posible? 1 Answer

How to wait for unity webplayer to load and then invoke its function? 0 Answers

change player possition via url 0 Answers

Connecting an html web page with unity web player 0 Answers

Why can't I build Web Player in Unity while I have no problems with building standalone versions? 2 Answers


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