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, ...

Get Unity Multiplayer Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.