void Update() { input = ard.ReadFromArduino(200); if (input == null) { return; } string[] output = input.Split(new string[] { "," }, System.StringSplitOptions.None); //print (output[0] +", "+ output[1] +", "+ output[2] +", "+ output[3]); gunAngle = new Vector3(GetFloat(output[0], 0f), GetFloat(output[1], 0f), GetFloat(output[2], 0f)); transform.localEulerAngles = new Vector3(-gunAngle.x - loc.localEulerAngles.x, -gunAngle.z, +loc.localEulerAngles.z); print(gunAngle); fire = Mathf.FloorToInt(GetFloat(output [3], 0f)); print(fire); }
void FixedUpdate() { if (generator.dead) { StartCoroutine(Waiting()); } if (timer >= 2 && !initialized) { initialized = true; communicator.WriteToArduino("N8\n"); } else if (!initialized) { } { timer += Time.deltaTime; } if (initialized) { if (oldPower != Mathf.Clamp(generator.maxLitRooms, 2, 7)) { communicator.WriteToArduino("P" + Mathf.Clamp(generator.maxLitRooms, 2, 7) + "\n"); oldPower = Mathf.Clamp(generator.maxLitRooms, 2, 7); } communicator.WriteToArduino("S\n"); string inPut = communicator.ReadFromArduino(50); Debug.Log(inPut); if (inPut != null && inPut != "INVALID") { char[] charArray = inPut.ToCharArray(); for (int i = 11; i < charArray.Length; i++) { //Debug.Log(charArray[i]); if (charArray[i] == '1') { generator.triggerRooms[i - 11].isLit = true; } if (charArray[i] == '0') { generator.triggerRooms[i - 11].isLit = false; } } } } }
void Update() { //If the game is over and the player has pressed some input... if (gameOver && Input.GetMouseButtonDown(0)) { //...reload the current scene. SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); } // Add Arduino connect.WriteToArduino("PING"); string s = connect.ReadFromArduino(10000); //Debug.Log(s); string[] block = s.Split(null); dataX = int.Parse(block[0]); dataY = int.Parse(block[1]); dataW = int.Parse(block[2]); dataH = int.Parse(block[3]); // Log file for data received from Arduino > output in the console of Unity3D //Debug.Log("x: " + dataX + " y: " + dataY + " w: " + dataW + " h: " + dataH); //Debug.Log("value1: " + (dataX - dataW) + " value2: " + (dataY - dataH)); // If size of block bigger than 15, then it is recognized as a pushing interaction // This information read by 'Bird.cs' if (dataX - dataW > 15 && dataY - dataH > 15) { pushing = true; } else { pushing = false; } //Debug.Log(pushing); }
void Update() { string value = arduino.ReadFromArduino(); //Read the information if (value == null) //if data is null [...] { // [...] then do nothing } else { vec3 = value.Split(','); //My arduino script returns a 4 part value (IE: 0,0,18,100,0,1) ////////////////////////////////////////////////////////////// x,y,speed,rudder,button1,button2 if (vec3[0] != "" && vec3[1] != "" && vec3[2] != "" && vec3[3] != "" && vec3[4] != "" && vec3[5] != "") //Check if all values are recieved { predkoscNastawa.value = float.Parse(vec3[2]); //parse spped value from serial pletwaNastawa.value = float.Parse(vec3[3]); //parse rudder value from serial CamX = 19 + float.Parse(vec3[0]); //parse X axis value CamY = 90 + float.Parse(vec3[1]); //parse Y axis value Kamera.transform.rotation = Quaternion.Euler(CamX, CamY + COG, 0); //rotates camera if (int.Parse(vec3[4]) == 0 && pause == 0) //pause simulation { Time.timeScale = 0; pause = 1; } if (int.Parse(vec3[5]) == 0 && pause == 1) //unpause simulation { Time.timeScale = 1; pause = 0; } } } predkosc.text = predkoscNastawa.value.ToString() + " %"; pletwa.text = pletwaNastawa.value.ToString() + " °"; if (predkoscAktualna != predkoscNastawa.value * predkoscMax / 100) { predkoscAktualna = Mathf.Lerp(predkoscAktualna, (predkoscMax * predkoscNastawa.value) / 100, 0.05f * Time.deltaTime); predkoscAktHUD.text = predkoscAktualna.ToString("0.0") + " kn"; } pletwaAkt = Mathf.MoveTowards(pletwaAkt, pletwaNastawa.value, 1f * Time.deltaTime); predkoscAktualna = Mathf.MoveTowards(predkoscAktualna, (predkoscMax * predkoscNastawa.value) / 100, 0.05f * Time.deltaTime); if (predkoscAktualna != 0) { ROT += (K * (pletwaAkt) - ROT) * Time.deltaTime; ROTAktHUD.text = ROT.ToString("0.0") + " °/s"; COG += ROT * Time.deltaTime; COGAktHUD.text = COG.ToString("0.0") + " °"; { x += predkoscAktualna * Time.deltaTime * Mathf.Sin(COG * Mathf.PI / 180); z += predkoscAktualna * Time.deltaTime * Mathf.Cos(COG * Mathf.PI / 180); transform.position = new Vector3(2100 + z, 500, 1900 - x); transform.rotation = Quaternion.Euler(0, COG, 0); wychylenieAktHUD.text = pletwaAkt.ToString("0") + " °"; } } arduino.WriteToArduino(predkoscAktHUD.text); }