- Home /
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
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
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?
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);
}
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!
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.
Your answer
Follow this Question
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