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, we can yield a WWW object, which will cause Unity to pause our function and resume it once the WWW request has finished (the WWW request itself is handled asynchronously in the background).
First, we'll create a MonoBehaviour
class to accomplish this...