[英]How can I make two objects stick together on collision? (unity 3d ) C#
[英]How can i send information from two different arduino boards to unity 3d c#
我正在使用兩個mpu6050傳感器,2個arduino板(1個arduino Mega和1個Arduino Uno)和統一3d。 每塊板都連接了一個mpu6050,它應該將收到的信息發送到統一。 我有麻煩從統一獲取數據(我從Arduino的IDE查看信息沒有問題)我使用兩個不同的COM,每個板1。
使用我當前的統一代碼即時出現問題,因為當我嘗試調試它時它會崩潰,當它沒有發送時會發送一個例外情況,例如:
Ports.io access denied
我有以下arduino代碼(它只恢復到影響這個問題的部分):
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println(map((ypr[2] * 180/M_PI),-90,90,0,360));
delay(20);
}
注意:MPU從-90到90發送值,所以我使用map函數來轉換0到360范圍內的值
這是統一代碼(我有兩個不同的代碼,但唯一的區別是它說“COM4”,另一個說“COM3”):
using UnityEngine;
using System.Collections;
using System.IO.Ports;
public class Mover_Con_Arduino : MonoBehaviour
{
SerialPort sp = new SerialPort("COM4", 9600);
void Start()
{
}
void Update()
{
if (!sp.IsOpen)
{
sp.Open();
}
float rot = float.Parse (sp.ReadLine ());
transform.localEulerAngles = new Vector3 (rot, 0, 0);
print (rot);
}
}
我正在做的是使用從arduino發送到Unity的值來旋轉游戲對象
我最好的猜測是sp.Open()無法打開COM端口並在sp.ReadLine()上拋出異常;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.