//Called once per frame, polls for inputs of all kinds void Update() { delay_timer += 1; //Quit with Q if (Input.GetKeyDown(KeyCode.Q)) { print(":)"); System.Diagnostics.Process.GetCurrentProcess().Kill(); } //Option Selection Keys if (Input.GetKeyDown(KeyCode.A)) { Selector.prev_option(); } if (Input.GetKeyDown(KeyCode.D)) { Selector.next_option(); } //Manual Click Key - DON'T DO THIS ON THE GAMEPLAY SCREEN - LEADS TO WEIRD BEHAVIOR if (Input.GetKeyDown(KeyCode.S) && SceneManager.GetActiveScene().name != "Gameplay") { Manual_Click.click(); } //Color Changing Keys if (Input.GetKeyDown(KeyCode.J)) { ColorChange.ChangeColor(0); } if (Input.GetKeyDown(KeyCode.K)) { ColorChange.ChangeColor(1); } if (Input.GetKeyDown(KeyCode.L)) { ColorChange.ChangeColor(2); } //Fuel and Angle Controllers if (Input.GetKey(KeyCode.F)) { GameState.select_fuel(); } else { GameState.unselect_fuel(); } if (Input.GetKey(KeyCode.G)) { GameState.select_angle(); } else { GameState.unselect_angle(); } }
//This function handles the mapping of different Arduino inputs, //noted as arg.Value, into actual function calls for different parts //of the game. private void Serial_OnButtonPressed(object sender, ArduinoEventArg arg) { if (delay_timer >= 2) { //Left Arrow if (arg.Value == 1) { UnityMainThreadDispatcher.Instance().Enqueue(() => Selector.prev_option()); delay_timer = 0; } //Launch-OK Button if (arg.Value == 0) { UnityMainThreadDispatcher.Instance().Enqueue(() => { //If on the gameplay screen, this button acts as the ENTER key if (SceneManager.GetActiveScene().name == "Gameplay") { InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN); } //Otherwise it acts as a mouse click else { Manual_Click.click(); } }); delay_timer = 0; } //Right Arrow if (arg.Value == 2) { UnityMainThreadDispatcher.Instance().Enqueue(() => Selector.next_option()); delay_timer = 0; } //Red Rutton if (arg.Value == 3) { UnityMainThreadDispatcher.Instance().Enqueue(() => InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_J)); delay_timer = 0; } //Green Button if (arg.Value == 4) { UnityMainThreadDispatcher.Instance().Enqueue(() => InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_K)); delay_timer = 0; } //Blue Button if (arg.Value == 5) { UnityMainThreadDispatcher.Instance().Enqueue(() => InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_L)); delay_timer = 0; } } }