每次按下 Arduino 上的按钮时,我都需要我的脚本转到下一个摄像头,我就是无法让它工作,有人可以帮我吗?
我让 Arduino 与 Anity 通信,但我无法理解相机切换部分。
有人能告诉我如何让一个按钮按下跳到下一个相机,所以我只需要一个按钮来显示所有相机的
using UnityEngine;
using System.Collections;
using Uniduino;
#if (UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5)
public class DigitalRead : Uniduino.Examples.DigitalRead { } // for unity 3.x
#endif
namespace Uniduino.Examples
{
public class digitalread2 : MonoBehaviour {
public Arduino arduino;
public int pin = 2;
public int pinValue;
public int testLed = 11;
public int licht;
public int enable;
public int val = 0;
public GameObject cam1;
public GameObject cam2;
void Start ()
{
arduino = Arduino.global;
arduino.Log = (s) => Debug.Log("Arduino: " +s);
arduino.Setup(ConfigurePins);
cam1 = GameObject.Find ("cam1");
}
void ConfigurePins ()
{
arduino.pinMode(pin, PinMode.INPUT);
arduino.reportDigital((byte)(pin/8), 1);
// set the pin mode for the test LED on your board, pin 13 on an Arduino Uno
arduino.pinMode(testLed, PinMode.OUTPUT);
}
void Update ()
{
// read the value from the digital input
enable = arduino.digitalRead (pin);
licht = arduino.digitalRead (pin);
pinValue = arduino.digitalRead(pin);
// apply that value to the test LED
arduino.digitalWrite(testLed,pinValue);
Debug.Log(pinValue);
val = arduino.digitalRead (pin);
arduino.digitalWrite (testLed, val);
val = cam1.active = false;
val = cam2.active = true;
}
}
}