- Home /
Can anyone give me an example of how unity browser communication works with .NET MVC and Unity?
I'm constantly referred to this page: https://docs.unity3d.com/Documentation/Manual/UnityWebPlayerandbrowsercommunication.html
But I'm still relatively new to web development, callbacks, AJAX, POST, etc..
So, I'd like to see an example of how everything ties together to make calls back from Unity to Browser?
For example, if I wanted the browser to detect the unity web player is still there after x amount of seconds, how do I do that without interfering with the web player functionality? Do I have to tie the script to a game object? I don;t want to run an alert every couple of seconds but a background browser/unity communication.
Answer by Sildaekar · Mar 10, 2014 at 06:43 PM
If you are wanting to know about what goes on "behind the scenes" so to say, I would suggest reading up on TCP/IP, as far as GET, POST, etc goes try looking up more on HTTP Methods.
Why not use the Unity get/post system?
https://docs.unity3d.com/Documentation/ScriptReference/WWW.html
I'm still relatively new to web development, callbacks, AJAX, POST, etc..So, I'd like to see an example of how everything ties together to make calls back from Unity to Browser?
I Inferred that they were asking more about protocols and the inner workings of how unity ties in with the web browser. POST, GET, etc. Are web protocols, WWW is a library that helps in using these protocols (among other things).
For example, if I wanted the browser to detect the unity web player is still there after x amount of seconds, how do I do that without interfering with the web player functionality? Do I have to tie the script to a game object and then in the script, have something fire up?
In that case, if the web player is not there then the application is closed, and I would imagine the page would be closed too.
If you are wanting to make a timer to see if the player is still open after X seconds, just make a simple timer within the game. Otherwise if you are just wanting to see if the page is still open, make a Javascript(not UnityScript) timer and place it somewhere in the webpage.
For example, if I had a session time out script that will lock out my webpage after X amount of $$anonymous$$utes due to inactivity and I want it to detect that someone is hitting the web player with clicks or actions, so that it won't lock the webpage because it can't detect what's going in the unity web player. So I was wondering, what's the best way to communicate to the browser to say that, "Hey, someone's still working here" ever so often so that the user is not logged out due to inactivity with the web player on.
Answer by fafase · Mar 10, 2014 at 06:38 PM
Well it is all in the docs. I would guess you want to have a method in your HTML file written in Javascript for instance (web js). This below goes on your html file :
<script type="text/javascript" language="javascript">
<!--
function OpenUnityCom()
{
window.open("http://www.unity3d.com");
}
-->
</script>
Then in any of your scripts, just decide where and when it should be called:
void Start(){
Application.ExternalCall( "OpenUnityCom");
}
And this is all about it.
For example, if I wanted the browser to detect the unity web player is still there after x amount of seconds, how do I do that without interfering with the web player functionality? Do I have to tie the script to a game object?
Your answer
Follow this Question
Related Questions
Get token back in unity 0 Answers
WWW class and Digest Authentication 0 Answers
How can i pass the post data of a server side page to unity? 1 Answer
How do I connect to a server in LAN from a different computer? I'm using socket.io and nodejs 1 Answer
Easily getting variable values from WebGL in Browser 2 Answers