void Update() { if (BtConnector.isConnected()) { if (BtConnector.available()) //check if there's an available data { messageFromMC = BtConnector.readLine(); //hold the data in messageFromMC //cause BtConnector.read () will delete the buffer if (messageFromMC.Length > 0) // recheck if there's an available data //this check is more important than BtConnector.available () //actually you could delete BtConnector.available () with no effect. { messages.Add(messageFromMC); //add the string to the list if (labelHeight * messages.Count >= (height - labelHeight)) { scrollPosition.y += labelHeight; //it will slide the ScrollView down } //if the whole screen filled with messages if (labelHeight * messages.Count >= height * 2) { messages.RemoveAt(0); //when the ScrollView filled ,delet old messages } } } } //read control data from the Module. controlData = BtConnector.readControlData(); }
public void Disconnect() { if (BtConnector.isConnected()) { BtConnector.close(); } }
void UpdateView() { ArmButton.SetActive(!Armed && BtConnector.isConnected()); DisArmButton.SetActive(Armed && BtConnector.isConnected()); //JoySticks.SetActive (BtConnector.isConnected ()); if (BtConnector.isConnected()) { ButtonConnect.SetActive(false); ButtonDisconnect.SetActive(true); } else { if (BtConnector.isDevicePicked) { ButtonConnect.SetActive(true); } else { ButtonConnect.SetActive(false); } ButtonDisconnect.SetActive(false); } }
void OnGUI() { GUIStyle style = GUI.skin.GetStyle("label"); style.fontSize = 20; if (!connected && GUI.Button(gRect, "Connect")) //the Connect button will disappear when connecttion done // and appear again if it disconnected { if (!BtConnector.isBluetoothEnabled()) { BtConnector.askEnableBluetooth(); } else { BtConnector.connect(); } } connected = BtConnector.isConnected(); //check connection status scrollPosition = GUI.BeginScrollView(new Rect(0, height * 0.1f, Screen.width, height), scrollPosition, new Rect(0, 0, Screen.width, height * 2)); for (int i = 0; i < messages.Count; i++) //display the List of messages { GUI.Label(new Rect(0, labelHeight * i, Screen.width, labelHeight), messages[i]); } GUI.EndScrollView(); messageToMC = GUI.TextField(new Rect(0, Screen.height * 0.9f, Screen.width * 0.9f, Screen.height * 0.1f), messageToMC); if (GUI.Button(new Rect(Screen.width * 0.9f, Screen.height * 0.9f, Screen.width * 0.1f, Screen.height * 0.1f), "Send")) { byte[] bytes = System.Text.Encoding.UTF8.GetBytes(messageToMC + '\n'.ToString()); //convert string to array of bytes and add a new line BtConnector.sendBytes(bytes); } if (GUI.Button(new Rect(Screen.width * 0.9f, 0, Screen.width * 0.1f, Screen.height * 0.1f), "Close Connection")) { BtConnector.close(); connected = false; } GUI.Label(new Rect(0, 0, Screen.width * 0.9f, Screen.height * 0.1f), "From Plugin : " + controlData); }
public void Connect() { if (!BtConnector.isBluetoothEnabled()) { BtConnector.askEnableBluetooth(); } else { _lastNameEnteredToConnect = deviceNameInput.text; BtConnector.moduleName(deviceNameInput.text); //incase User Changed the Bluetooth Name int result = BtConnector.connect(); } connected = BtConnector.isConnected();//check connection status }
void OnGUI() { GUI.Label(new Rect(0, 0, Screen.width * 0.15f, Screen.height * 0.1f), "Module Name "); if (BtConnector.isConnected()) { if (GUI.Button(new Rect(0, Screen.height * 0.5f, Screen.width, Screen.height * 0.1f), "RequestIMU")) { UFoneInterface.RequestIMU(); } if (GUI.Button(new Rect(0, Screen.height * 0.6f, Screen.width, Screen.height * 0.1f), "RequestRC")) { UFoneInterface.RequestRC(); } if (GUI.Button(new Rect(0, Screen.height * 0.7f, Screen.width, Screen.height * 0.1f), "ARM")) { UFoneInterface.SetRawRC(1400, 1410, 1420, 1000, 1950, 1500, 1500, 1501); } if (GUI.Button(new Rect(0, Screen.height * 0.8f, Screen.width, Screen.height * 0.1f), "DisArm")) { UFoneInterface.SetRawRC(1400, 1410, 1420, 1000, 1050, 1500, 1500, 1500); } } else { if (GUI.Button(new Rect(0, Screen.height * 0.4f, Screen.width, Screen.height * 0.1f), "Try Connect")) { if (!BtConnector.isBluetoothEnabled()) { BtConnector.askEnableBluetooth(); } else { BtConnector.connect(); } } if (GUI.Button(new Rect(0, Screen.height * 0.9f, Screen.width, Screen.height * 0.1f), "Show")) { BtConnector.showDevices(); } } }
void OnGUI() { GUIStyle style = GUI.skin.GetStyle("label"); style.fontSize = 20; if (!BtConnector.isConnected() && GUI.Button(gRect, "Connect")) //the Connect button will disappear when connecttion done // and appear again if it disconnected { if (!BtConnector.isBluetoothEnabled()) { BtConnector.askEnableBluetooth(); } else { BtConnector.connect(); } } scrollPosition = GUI.BeginScrollView(new Rect(0, height * 0.1f, Screen.width, height), scrollPosition, new Rect(0, 0, Screen.width, height * 2)); for (int i = 0; i < messages.Count; i++) //display the List of messages { GUI.Label(new Rect(0, labelHeight * i, Screen.width, labelHeight), messages[i]); } GUI.EndScrollView(); messageToMC = GUI.TextField(new Rect(0, Screen.height * 0.9f, Screen.width * 0.9f, Screen.height * 0.1f), messageToMC); if (GUI.Button(new Rect(Screen.width * 0.9f, Screen.height * 0.9f, Screen.width * 0.1f, Screen.height * 0.1f), "Send")) { BtConnector.sendString(messageToMC); } if (GUI.Button(new Rect(Screen.width * 0.9f, 0, Screen.width * 0.1f, Screen.height * 0.1f), "Close Connection")) { BtConnector.close(); } GUI.Label(new Rect(0, 0, Screen.width * 0.9f, Screen.height * 0.1f), "From Plugin : " + controlData); }
public static bool autoConnect(float time) { int tmp = -3; while (!BtConnector.isConnected() && time > 0) { time -= Time.deltaTime; if (tmp == -3) { BtConnector.connect(); } tmp = BtConnector.controlData(); } return(BtConnector.isConnected()); }
void Update() { if (BtConnector.isConnected() && BtConnector.available()) //check connection status { messageFromMC = BtConnector.readBuffer(); //read bytes till a new line or a max of 100 bytes if (messageFromMC.Length > 0) { messages.Add(System.Text.Encoding.UTF8.GetString(messageFromMC)); //convert array of bytes into string if (labelHeight * messages.Count >= (height - labelHeight)) { scrollPosition.y += labelHeight; //slide the Scrollview down,when the screen filled with messages } if (labelHeight * messages.Count >= height * 2) { messages.RemoveAt(0); //remove old messages,when ScrollView filled } } } //read control data from the Module. controlData = BtConnector.readControlData(); }
void OnGUI() { GUI.Label(new Rect(0, 0, Screen.width * 0.15f, Screen.height * 0.1f), "Module Name "); stringToEdit = GUI.TextField(new Rect(Screen.width * 0.15f, 0, Screen.width * 0.8f, Screen.height * 0.1f), stringToEdit); GUI.Label(new Rect(0, Screen.height * 0.2f, Screen.width, Screen.height * 0.1f), "Arduino Says : " + ByteArrayToString(buffer)); GUI.Label(new Rect(0, Screen.height * 0.3f, Screen.width, Screen.height * 0.1f), "from PlugIn : " + BtConnector.readControlData()); if (GUI.Button(new Rect(0, Screen.height * 0.4f, Screen.width, Screen.height * 0.1f), "Connect")) { if (!BtConnector.isBluetoothEnabled()) { BtConnector.askEnableBluetooth(); } else { BtConnector.connect(); } } ///the hidden code here let you connect directly without askin the user /// if you want to use it, make sure to hide the code from line 23 to lin 33 /* * if( GUILayout.Button ("Connect")){ * * startConnection = true; * * } * * if(GUI.Button(new Rect(0,Screen.height*0.4f,Screen.width,Screen.height*0.1f), "Connect")) * { * if (!BtConnector.isBluetoothEnabled ()){ * BtConnector.enableBluetooth(); * * } else { * * BtConnector.connect(); * * startConnection = false; * * } * * } */ ///////////// if (GUI.Button(new Rect(0, Screen.height * 0.6f, Screen.width, Screen.height * 0.1f), "sendChar")) { if (BtConnector.isConnected()) { BtConnector.sendChar('h'); BtConnector.sendChar('e'); BtConnector.sendChar('l'); BtConnector.sendChar('l'); BtConnector.sendChar('o'); BtConnector.sendChar('\n'); //because we are going to read it using .readLine() which reads lines. } } if (GUI.Button(new Rect(0, Screen.height * 0.5f, Screen.width, Screen.height * 0.1f), "sendString")) { if (BtConnector.isConnected()) { BtConnector.sendString("Hii"); BtConnector.sendString("you can do this"); } } if (GUI.Button(new Rect(0, Screen.height * 0.7f, Screen.width, Screen.height * 0.1f), "Close")) { BtConnector.close(); } if (GUI.Button(new Rect(0, Screen.height * 0.8f, Screen.width, Screen.height * 0.1f), "readData")) { //fromArduino = BtConnector.readLine(); buffer = BtConnector.readBuffer(); } if (GUI.Button(new Rect(0, Screen.height * 0.9f, Screen.width, Screen.height * 0.1f), "change ModuleName")) { BtConnector.moduleName(stringToEdit); } }
void Start() { DontDestroyOnLoad(this); joystick = GameObject.Find("MobileJoystick"); jumpButton = GameObject.Find("JumpButton"); health = GameObject.FindWithTag("Health"); header = false; counter = 0; buffer5HasRead = false; calibrateControllerCounter = 0; posXCali = 0; posYCali = 0; newStartPosX = 0; newStartPosY = 0; //A bluetooth controller is CONNECTED, don't use the virtual joystick and button if (BtConnector.isConnected()) { buffer = BtConnector.readBuffer(); counter = 0; buffer5HasRead = false; for (int i = 0; i < buffer.Length; i++) { if (buffer [i] == 10 && counter == 0) { header = true; } else if (header == true) { buffer5 [counter] = buffer [i]; counter++; if (counter == 5) { header = false; counter = 0; buffer5HasRead = true; break; } } } if (buffer5HasRead == true) { posX = (sbyte)buffer5 [1]; posY = (sbyte)buffer5 [2]; button = (sbyte)buffer5 [3]; parity = (sbyte)buffer5 [4]; } //startPos = new Vector3(10,-4, 0); //TODO: Change the default startPos for the controller startPos = new Vector3(-posX, posY, 0); //TODO: Change the default startPos for the controller } //If a bluetooth controller is NOT CONNECTED, use the virtual joystick and button else { if (joystick) { startPos = joystick.transform.position; } if (jumpButton) { EventTrigger eventTrigger = jumpButton.GetComponent <EventTrigger> (); EventTrigger.Entry entry = new EventTrigger.Entry(); entry.eventID = EventTriggerType.PointerDown; entry.callback = new EventTrigger.TriggerEvent(); UnityEngine.Events.UnityAction <BaseEventData> callback = new UnityEngine.Events.UnityAction <BaseEventData> (FireBullet); entry.callback.AddListener(callback); eventTrigger.delegates.Add(entry); //eventTrigger.enabled = false; } } }
// Rotate player in sync with joystick and move in that direction void FixedUpdate() { if (BtConnector.isConnected()) { buffer = BtConnector.readBuffer(); counter = 0; buffer5HasRead = false; for (int i = 0; i < buffer.Length; i++) { if (buffer [i] == 10 && counter == 0) { header = true; } else if (header == true) { buffer5 [counter] = buffer [i]; counter++; if (counter == 5) { header = false; counter = 0; buffer5HasRead = true; break; } } } //If successfully read, buffer5 contains the 5 bytes (excluding the newline) sent by the controller //buffer5[0] = 4 //buffer5[1] = p->x //buffer5[2] = p->y //buffer5[3] = p->buttons //buffer5[4] = p->parity if (buffer5HasRead == true) { posX = (sbyte)buffer5 [1]; posY = (sbyte)buffer5 [2]; button = (sbyte)buffer5 [3]; parity = (sbyte)buffer5 [4]; } //Eliminate any bad initial conditions introduced during the menu scene if (Mathf.Abs(startPos.x) > 5 || Mathf.Abs(startPos.y) > 5) { startPos = new Vector3(-posX, posY, 0); } //Fire bullet if A (has a value of 0b00010) button is pressed if (button == 2) { FireBullet2(); //button = 0; } newPos = new Vector3(-posX, posY, 0); Vector3 diff = newPos - startPos; diff.Normalize(); float rot_z = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg; var pos = this.transform.position; if ((Mathf.Abs(diff.x) > 0.1 || Mathf.Abs(diff.y) > 0.1) && GetComponent <NetworkView> ().isMine) { transform.rotation = Quaternion.Euler(0f, 0f, rot_z - 90); GetComponent <Rigidbody2D> ().AddForce(gameObject.transform.up * speed); } // Prevent the player from going off screen if (pos.x < 25) { pos.x = 25; } else if (pos.x > Screen.width - 25) { pos.x = Screen.width - 25; } if (pos.y < 25) { pos.y = 25; } else if (pos.y > Screen.height - 25) { pos.y = Screen.height - 25; } this.transform.position = pos; } else { if (joystick) { Vector3 diff = joystick.transform.position - startPos; diff.Normalize(); float rot_z = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg; var pos = this.transform.position; if ((Mathf.Abs(diff.x) > 0.1 || Mathf.Abs(diff.y) > 0.1) && GetComponent <NetworkView> ().isMine) { transform.rotation = Quaternion.Euler(0f, 0f, rot_z - 90); GetComponent <Rigidbody2D> ().AddForce(gameObject.transform.up * speed); } // Prevent the player from going off screen if (pos.x < 25) { pos.x = 25; } else if (pos.x > Screen.width - 25) { pos.x = Screen.width - 25; } if (pos.y < 25) { pos.y = 25; } else if (pos.y > Screen.height - 25) { pos.y = Screen.height - 25; } this.transform.position = pos; } } }
void OnGUI() { GUI.Label(new Rect(0, 0, Screen.width * 0.15f, Screen.height * 0.1f), "Module Name "); stringToEdit = GUI.TextField(new Rect(Screen.width * 0.15f, 0, Screen.width * 0.8f, Screen.height * 0.1f), stringToEdit); GUI.Label(new Rect(0, Screen.height * 0.2f, Screen.width, Screen.height * 0.1f), "Arduino Says : " + fromArduino); GUI.Label(new Rect(0, Screen.height * 0.3f, Screen.width, Screen.height * 0.1f), "from PlugIn : " + BtConnector.readControlData()); if (GUI.Button(new Rect(0, Screen.height * 0.4f, Screen.width, Screen.height * 0.1f), "Connect")) { if (!BtConnector.isBluetoothEnabled()) { BtConnector.askEnableBluetooth(); } else { BtConnector.moduleName(stringToEdit); //incase User Changed the Bluetooth Name BtConnector.connect(); } } ///the hidden code here let you connect directly without askin the user /// if you want to use it, make sure to hide the code from line 23 to lin 33 /* * if( GUILayout.Button ("Connect")){ * * startConnection = true; * * } * * if(GUI.Button(new Rect(0,Screen.height*0.4f,Screen.width,Screen.height*0.1f), "Connect")) * { * if (!BtConnector.isBluetoothEnabled ()){ * BtConnector.enableBluetooth(); * * } else { * * BtConnector.connect(); * * startConnection = false; * * } * * } */ ///////////// if (GUI.Button(new Rect(0, Screen.height * 0.6f, Screen.width, Screen.height * 0.1f), "sendChar")) { if (BtConnector.isConnected()) { BtConnector.sendChar('h'); BtConnector.sendChar('e'); BtConnector.sendChar('l'); BtConnector.sendChar('l'); BtConnector.sendChar('o'); BtConnector.sendChar('\n'); //because we are going to read it using .readLine() which reads lines. //don't call the send method multiple times unless you really need to, because it will kill performance. } } if (GUI.Button(new Rect(0, Screen.height * 0.5f, Screen.width, Screen.height * 0.1f), "sendString")) { if (BtConnector.isConnected()) { BtConnector.sendString("Hii"); BtConnector.sendString("you can do this"); //BtConnector.sendBytes(new byte[] {55,55,55,10}); //don't call the send method multiple times unless you really need to, because it will kill performance. } } if (GUI.Button(new Rect(0, Screen.height * 0.7f, Screen.width, Screen.height * 0.1f), "Close")) { BtConnector.close(); } if (GUI.Button(new Rect(0, Screen.height * 0.8f, Screen.width, Screen.height * 0.1f), "readData")) { if (BtConnector.available()) { fromArduino = BtConnector.readLine(); } } if (GUI.Button(new Rect(0, Screen.height * 0.9f, Screen.width, Screen.height * 0.1f), "change ModuleName")) { BtConnector.moduleName(stringToEdit); } }
void Update() { //q1.transform.Rotate(0.1f, 0, 0.1f); //q2.transform.Rotate(-0.1f, 0, -0.1f); connected = BtConnector.isConnected();//check connection status if (BtConnector.isConnected() != _connectButtonStatus) { _connectButtonStatus = BtConnector.isConnected(); connectButtonImage.color = _connectButtonStatus == true ? connectedButtonColour : notConnectedButtonColour; connectButtonText.text = _connectButtonStatus == true ? "connected!" : "connect"; if (_connectButtonStatus == true) { PlayerPrefs.SetString("lastConnectedDeviceName", _lastNameEnteredToConnect); if (ifcal) { UIManager.Instance.notConnectedGameErrorObject.SetActive(false); } } else { UIManager.Instance.notConnectedGameErrorObject.SetActive(true); UIManager.Instance.setMinToggle.isOn = false; UIManager.Instance.setMaxToggle.isOn = false; fullyCalibrated = false; // TODO : pause game and allow reconnection if (GameManager.Instance != null) { GameManager.Instance.ExitGame(); } } } if (BtConnector.isConnected() && BtConnector.available()) //check connection status { messageFromMC = BtConnector.readBuffer(); //read bytes till a new line or a max of 100 bytes if (messageFromMC.Length > 0) { if (messageFromMC.Length == 16) { qq1.w = (float)(messageFromMC[0] * 256 + messageFromMC[1]); // (10000.0f); qq1.x = (float)(messageFromMC[2] * 256 + messageFromMC[3]); // (10000.0f); qq1.y = (float)(messageFromMC[4] * 256 + messageFromMC[5]); // (10000.0f); qq1.z = (float)(messageFromMC[6] * 256 + messageFromMC[7]); // (10000.0f); qq2.w = (float)(messageFromMC[8] * 256 + messageFromMC[9]); // (10000.0f); qq2.x = (float)(messageFromMC[10] * 256 + messageFromMC[11]); // (10000.0f); qq2.y = (float)(messageFromMC[12] * 256 + messageFromMC[13]); // (10000.0f); qq2.z = (float)(messageFromMC[14] * 256 + messageFromMC[15]); // (10000.0f); if (qq1.w >= 32768) { qq1.w = qq1.w - 65536; } if (qq1.x >= 32768) { qq1.x = qq1.x - 65536; } if (qq1.y >= 32768) { qq1.y = qq1.y - 65536; } if (qq1.z >= 32768) { qq1.z = qq1.z - 65536; } if (qq2.w >= 32768) { qq2.w = qq2.w - 65536; } if (qq2.x >= 32768) { qq2.x = qq2.x - 65536; } if (qq2.y >= 32768) { qq2.y = qq2.y - 65536; } if (qq2.z >= 32768) { qq2.z = qq2.z - 65536; } ////////////////////////////////////////////////////////// if (qq1.w > 10000) { qq1.w -= 10000; } if (qq1.x > 10000) { qq1.x -= 10000; } if (qq1.y > 10000) { qq1.y -= 10000; } if (qq1.z > 10000) { qq1.z -= 10000; } if (qq2.w > 10000) { qq2.w -= 10000; } if (qq2.x > 10000) { qq2.x -= 10000; } if (qq2.y > 10000) { qq2.y -= 10000; } if (qq2.z > 10000) { qq2.z -= 10000; } qq1.w /= 10000; qq1.x /= 10000; qq1.y /= 10000; qq1.z /= 10000; qq2.w /= 10000; qq2.x /= 10000; qq2.y /= 10000; qq2.z /= 10000; float s1, s2; s1 = (qq1.w * qq1.w) + (qq1.x * qq1.x) + (qq1.y * qq1.y) + (qq1.z * qq1.z); s2 = (qq2.w * qq2.w) + (qq2.x * qq2.x) + (qq2.y * qq2.y) + (qq2.z * qq2.z); if ((int)(s1 * 100) == 99 || (int)(s1 * 100) == 100) { q1.transform.rotation = qq1; } if ((int)(s2 * 100) == 99 || (int)(s2 * 100) == 100) { q2.transform.rotation = qq2; } if (((int)(s1 * 100) == 99 || (int)(s1 * 100) == 100) && ((int)(s2 * 100) == 99 || (int)(s2 * 100) == 100)) { Angletext.text = "Not Set!"; if (ifcal) { q3.transform.rotation = qq3 = product(divideQbyR(qq2, qq2_0), qq1_0); diff2 = divideQbyR(qq1, qq3); //float currentAngle = Quaternion.Angle(qqzero, diff2); arm.transform.localRotation = diff2;//current position v3cur = (toparm.transform.position - sp.transform.position); v3cur_ = Vector3.ProjectOnPlane(v3cur, Vector3.Cross(v3max, v3min)); currentAngle = Vector3.Angle(v3min, v3cur_); if (Mathf.Abs((Vector3.Angle(v3min, v3max) + Vector3.Angle(v3min, v3cur_)) - Vector3.Angle(v3max, v3cur_)) < 1) { currentAngle *= -1; } else if (Mathf.Abs(Vector3.Angle(v3min, v3max) + Vector3.Angle(v3min, v3cur_) + Vector3.Angle(v3max, v3cur_) - 360) < 1) { currentAngle *= -1; } currentAngle = (angold * 3 + currentAngle) / 4.0f; Angletext.text = "\n min: " + v3min.ToString() + "\n v3cur: " + v3cur.ToString() + "\n v3cur_: " + v3cur_.ToString() + "\n angle mm: " + Vector3.Angle(v3min, v3max).ToString() + "\n angle n : " + Vector3.Angle(v3min, v3cur_).ToString() + "\n angle x : " + Vector3.Angle(v3max, v3cur_).ToString() + "\n CurrentAngle :" + currentAngle.ToString(); // don't want to increase max angle in hockey or pop pop //if (currentAngle > maxAngle && (Hockey.Instance == null || PopManager.instance != null)) // maxAngle = currentAngle; // if there is a gamemmanger in scene, it means we're acting on input if (GameManager.Instance != null) { // update image of current value GameManager.Instance.UpdateCurrentValue(minAngle, currentAngle, maxAngle); // check if we've reset bool hasReset = GameManager.Instance.hasResetToggle != null ? GameManager.Instance.hasResetToggle.isOn : true; // accept input within 10 % of the maximum angle if (GameManager.Instance.GameInProgress && !GameManager.Instance.locked && hasReset && (Mathf.InverseLerp(minAngle, maxAngle, currentAngle) > 0.90f || Input.GetKeyDown(KeyCode.Space))) { GameManager.Instance.Action(); } // else register a reset if we're within 10% of the minimum angle else if (GameManager.Instance.GameInProgress && !hasReset && Mathf.InverseLerp(minAngle, maxAngle, currentAngle) < 0.10f) { GameManager.Instance.hasResetToggle.isOn = true; } if (GameManager.Instance.GameInProgress) { thisGamesFrequencies.Add(currentAngle); thisGamesMaxAngles.Add(maxAngle); } } angold = currentAngle; } else { q3.transform.rotation = qq2; } } } } //if (t.text.Length > 500) // t.text = ""; //convert array of bytes into string /////////////////////////////// //if (labelHeight * messages.Count >= (height - labelHeight)) // scrollPosition.y += labelHeight;//slide the Scrollview down,when the screen filled with messages //if (labelHeight * messages.Count >= height * 2) // messages.RemoveAt (0);//remove old messages,when ScrollView filled } //read control data from the Module. controlData = BtConnector.readControlData(); }
void Update() { // Display current status of Bluetooth module statusText.text = BtConnector.readControlData(); // If already connected if (BtConnector.isConnected()) { objectReceiver.ActivateSensor(true); // Send PING if (!waitResponse) { BtConnector.sendString("PING"); waitResponse = true; } // Check for PONG (non-blocking) if (BtConnector.available()) { string response = BtConnector.readLine(); if (response.Length > 0) { waitResponse = false; if (response[0] == ' ') { // string to tell us whether or not to activate the stasis activateText.text = activateStasis; powerupText.text = response.Substring(3); activateStasis = response.Substring(1, 1); powerUpString = response.Substring(3); if (activateStasis[0] == '1') { objectReceiver.FireCharge(); } objectReceiver.PowerUp(float.Parse(powerUpString)); } else if (response == "PONG BUTTON ON") { bluetoothText.text = "Button On!"; } else if (response == "PONG BUTTON OFF") { bluetoothText.text = "..."; } else { bluetoothText.text = response; } } } else { bluetoothText.text = "Not Available"; } } else { bluetoothText.text = "Not Connected"; //BtConnector.connect(); } }