Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using PubNubAPI;
- public class pnVoteInput : MonoBehaviour
- {
- ///these variable are used to set up Pubnub
- public static PubNub dataServer;
- public string pubKey = "pub-c-a705a585-4407-4f88-8b83-ac846c45e13a";
- public string subKey = "sub-c-64587bc8-b0cf-11e6-a7bb-0619f8945a4f";
- public string channelName = "phoneRotations";
- ////
- public double rotX;
- public double rotY;
- public double rotZ;
- void Start ()
- {
- //This section establishes the parameters for connecting to Pubnub
- PNConfiguration connectionSettings = new PNConfiguration ();
- connectionSettings.PublishKey = pubKey;
- connectionSettings.SubscribeKey = subKey;
- connectionSettings.LogVerbosity = PNLogVerbosity.BODY;
- connectionSettings.Secure = true;
- ////////
- dataServer = new PubNub(connectionSettings); //make the connection to the server
- Debug.Log("Connected to Pubnub");
- //Subscribe to the channel specified above
- dataServer.Subscribe ()
- .Channels (new List<string> () { channelName } )
- .Execute();
- //define the function that is called when a new message arrives
- //unlike javascript it is named and defined all at once rather than linking to another function
- dataServer.SusbcribeCallback += (sender, evt) =>
- {
- SusbcribeEventEventArgs inMessage = evt as SusbcribeEventEventArgs;
- if (inMessage.MessageResult != null) //error check to insure the message has contents
- {
- //convert the object that holds the message contents into a Dictionary
- Dictionary<string, object> msg = inMessage.MessageResult.Payload as Dictionary<string, object>;
- rotX = (double)msg["rotX"];
- rotY = (double)msg["rotY"];
- rotZ = (double)msg["rotZ"];
- transform.eulerAngles = new Vector3((float)rotX,(float)rotY,(float)rotZ);
- }
- };
- }
- }
Add Comment
Please, Sign In to add comment