using System.Collections; using System.Collections.Generic; using UnityEngine; using PubNubAPI; public class ALexa : MonoBehaviour { PubNub pubnub; string AlexaVal; public Rigidbody rb; Vector3 m_EulerAngleVelocity; private int m_T = 0; public int flag = 0; private string s_T = "[0,0,0,0,0,0,0]"; private string s_M = "[0,0,0,0,0,0,0]"; // Start is called before the first frame update void Start() { m_EulerAngleVelocity = new Vector3(0, 20, 0); rb = GetComponent(); PNConfiguration pnConfiguration = new PNConfiguration(); pnConfiguration.SubscribeKey = "sub-c-404ad2cc-1410-11e7-bb8a-xxxxxxxxxx"; pnConfiguration.PublishKey = "pub-c-92ed06dd-cde5-460f-9047-xxxxxxxxxx"; pnConfiguration.Secure = false; Dictionary msg = new Dictionary(); pubnub = new PubNub(pnConfiguration); pubnub.Subscribe() .Channels(new List(){ "my_channel" }) .Execute(); } // Update is called once per frame void FixedUpdate() { Quaternion deltaRotation = Quaternion.Euler(m_EulerAngleVelocity * Time.deltaTime); if (flag == 1) { //transform.Translate(0,0,8f *Time.deltaTime); s_M = "[2,1,0,0,0,0,0]"; m_T = 55; } else if (flag == 2) { //transform.Translate(0,0,-8f *Time.deltaTime); s_M = "[1,2,0,0,0,0,0]"; m_T = 55; } else if (flag == 3) { //transform.Rotate(0,-10f *Time.deltaTime,0); s_M = "[1,1,0,0,0,0,0]"; m_T = 40; } else if (flag == 4) { //transform.Rotate(0,10f *Time.deltaTime,0); s_M = "[2,2,0,0,0,0,0]"; m_T = 40; } else if (flag == 5) { //transform.Translate(0,0,0); //transform.Rotate(0,0,0); s_M = "[2,1,0,0,0,0,0]"; m_T = 0; } else if (flag == 0) { s_M = "[2,1,0,0,0,0,0]"; m_T = 0; } s_T = m_T.ToString() + "," + m_T.ToString() + ",0,0,0,0,0"; string mssg = "{\"pType\":7,\"m_T\":[" + s_T + "],\"m_M\":" + s_M + "}"; gameObject.GetComponent ().SendValue (mssg); pubnub.SusbcribeCallback += (sender, e) => { SusbcribeEventEventArgs mea = e as SusbcribeEventEventArgs; if (mea.MessageResult != null) { Debug.Log("Payload from alexa: " + mea.MessageResult.Payload.ToString()); AlexaVal = mea.MessageResult.Payload.ToString(); if (AlexaVal == "forward" || AlexaVal == "initiate" ){ flag = 1; } else if (AlexaVal == "backward"){ flag = 2; } else if (AlexaVal == "left"){ flag = 3; } else if (AlexaVal == "right"){ flag = 4; } else if (AlexaVal == "takeOff"){ flag = 5; } } }; } }