Stap 4: Laat onze eenheid-code schrijven
Zorg ervoor dat uw projecten eenheid seriële communicatie door
1-bewerken > Projectinstellingen > player > scroll naar beneden voor optimalisatie en api-compatibiliteit wijzigen in .NET 2.0
2-nu we de hoofdcamera omzetten orthografische en de grootte ingesteld op 5 en ten slotte zijn positie te wijzigen
x = 9, y = -6
3 - het maken van een kubus en het script aan het koppelen
using UnityEngine;using System.Collections; using System.IO.Ports; public class axis : MonoBehaviour { private Vector3 temp; private SerialPort stream = new SerialPort( + "COM11", 9600); // Use this for initialization void Start () { stream.Open(); stream.ReadTimeout = 25; StartCoroutine(readString()); } // Update is called once per frame void Update () { } IEnumerator readString() { while (true) { if (stream.IsOpen) { try { string value = stream.ReadLine(); string[] values = value.Split(','); float x = int.Parse(values[0]); float y = -1 * (int.Parse(values[1])); x = x / 10f; y = y / 10f; temp = transform.position; temp.x = x; temp.y = y; transform.position = temp; } catch (System.Exception) { } } yield return null; } } }