I have looked at the network documentation for Unity and most examples seem to be related to networking your game for multiplayer. I am just looking to grab a JSON response from an api for dynamically generating a menu. Is there some good examples for doing just simple network calls to get a response from a web server?
Thanks
If you are using C# and not targeting Webplayer or iOS, you can use HttpWebRequest
and a library like Json.NET if you like (if you have past experience with these classes instance). You will likely need to spend a little extra time properly handling the request asychronously.
There is also Unity's WWW
class where you would inspect and parse the resulting text
property. The WWW
class has the advantage of requiring very little code to perform the request asynchronously.
Note that without making such a request asynchronously you can easily block progress in the rest of the game loop, which is almost always not desirable.
For access to a web based API it would be easiest to use the WWW class in Unity.
http://unity3d.com/support/documentation/ScriptReference/WWW.html
Make sure to check the documentation about using it asynchronously, or it can block execution while waiting for the web server to respond (or not respond).
http://unity3d.com/support/documentation/ScriptReference/index.Coroutines_26_Yield.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With