O'Reilly logo

Unity Multiplayer Games by Alan Stagner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Building a PubNub interface

Our system will make use of the built-in WWW class of Unity to make requests, and a very useful Unity script feature known as coroutines to asynchronously wait until the request is finished—since a web request can take a while to complete, we do not want our game loop to be paused while waiting for the server to respond.

Tip

In Unity, a coroutine is a way to semi-asynchronously execute some code by dividing the function into steps which can be performed across multiple frames. Coroutines "yield" values during execution. This value is interpreted by Unity and used to determine when to resume the coroutine. For instance, yielding null will cause Unity to pause our function and resume it on the next frame. In this case, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required