This is the official PubNub Unity SDK repository.
PubNub takes care of the infrastructure and APIs needed for the realtime communication layer of your application. Work on your app's logic and let PubNub handle sending and receiving data across the world in less than 100ms.
You will need the publish and subscribe keys to authenticate your app. Get your keys from the Admin Portal.
-
Open Unity Editor and navigate to Window -> Package Manager.
-
In the Package Manager window, click + and select Add package from git URL.
-
Paste the PubNub Unity package link and click Add.
https://github.com/pubnub/unity.git?path=/PubNubUnity/Assets/PubNub
-
In the editor menu bar, navigate to PubNub and click Set up templates.
-
Restart Unity Editor.
See the complete getting started guide and SDK documentation:
listener.onStatus += OnPnStatus;
listener.onMessage += OnPnMessage;
void OnPnStatus(Pubnub pn, PNStatus status) {
Debug.Log(status.Category == PNStatusCategory.PNConnectedCategory ? "Connected" : "Not connected");
}
void OnPnMessage(Pubnub pn, PNMessageResult<object> result) {
Debug.Log($"Message received: {result.Message}");
}
pubnub.Subscribe<string>().Channels(new[] { "TestChannel" }).Execute();
await pubnub.Publish().Channel("TestChannel").Message("Hello World from Unity!").ExecuteAsync();
// OR
await pubnub.Publish().Channel("TestChannel").Message(transform.position.GetJsonSafe()).ExecuteAsync();
If you need help or have a general question, contact support@pubnub.com.