### Subscribing and Publishing with PubNub in C# Source: https://github.com/pubnub/unity/blob/master/README.md Shows how to subscribe to a channel (`TestChannel`) and how to publish messages to that channel. Includes examples of publishing a simple string message and publishing a serialized object (like a transform position). Requires `await` for publish operations. ```C# pubnub.Subscribe().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(); ``` -------------------------------- ### Adding PubNub Event Listeners in C# Source: https://github.com/pubnub/unity/blob/master/README.md Demonstrates how to attach handler methods (`OnPnStatus`, `OnPnMessage`) to the `onStatus` and `onMessage` events of a PubNub listener object. The handler methods show basic logging of connection status and received messages. ```C# 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 result) { Debug.Log($"Message received: {result.Message}"); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.