-4

每次按下 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;



        }
    }
}
4

1 回答 1

0

GameObject cam1, cam2;
void Start(){
  cam1 = Find("camera_name");
  cam2 = Find("camera2_name");
  cam1.enabled = True;
  cam2.enabled = False;

void Update(){
  if(Input.GetButtonDown... // you need to  implement ur arduino && cam1,isActive())
      cam1.enabled = false;
      cam2.enabled = true;
  if(Input.GetButtonDown... // you need to  implement ur arduino && cam2.isActive()) {
      cam2.enabled = false;
      cam1.enabled = true;
}

可能有什么问题。我现在无法使用 Unity Tool。我也不确定你是否可以“cam1.enabled”。

于 2015-05-29T14:21:44.760 回答