- Home /
Control game via website
Just wanted to drop this quick question:
Is it possible to control a game via website. Meaning, can I add a button to the website that every visitor is able to press. And this button, for example, simply adds force to a cube to launch it in the air. The game is not, necessarily, run in WebGL and on the same website, but on a different machine.
If you could provide terms, topics or similar that I can look at to achieve this goal, that would be great. I found some resources but on different topics, that wouldn't apply to this concept.
Answer by sh_code · Jan 13, 2019 at 10:51 PM
you need your website to store the button click, and your game to query the website API, for example via JSON, so that the website tells it if the button was clicked.
it's a client-server thing.
website is the server, game is the client.
Thanks, allright, thought so... Thought there would be an easier way than this, but guess I'll get to it.
Answer by Alanisaac · Jan 13, 2019 at 11:46 PM
As @sh_code mentioned, one way is to have the game periodically query the website for button clicks. This design is an example of polling. The biggest pro of this design is that it's relatively simple to implement, but there could be issues with latency and server load, especially if you have more than one game/client connected to your website. Even so, polling is a good place to start, and you might find that polling is sufficient for your game in the long run!
I thought I'd throw out an alternative that allows your server to push messages to your client instead, in case you need it. One such protocol that supports pushing data is called WebSocket. WebSocket is a protocol that allows for two-way communication between two applications over TCP. There are a number of implementations for WebSocket, but I would check out socket.io-unity first, both because it is Unity-specific, and also because it has many examples to help you get started.
Hope that helps!
Oh, i forgot about WebSockets. However, I don't think the asker will be able to implement those, seeing he's completely new to the concept of client-server, so I'd still recommend to at least start with the polling approach, and maybe re-do it to websockets later, after he gets at least a bit familiar with the client-server concept.
Your answer
Follow this Question
Related Questions
Tell UnityWebRequest to trust invalid SSL certs 1 Answer
Which ways are available for a Unity program to communicate with other programs? 2 Answers
Server to server communication 1 Answer
SignalR 2.0 0 Answers
Unity Web Request 2 Answers