Created
December 11, 2018 19:40
-
-
Save jasonhbartlett/ed18709acabc8ef1e34bed276c5e32b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using AirSimUnity.DroneStructs; | |
using UnityEngine; | |
namespace AirSimUnity | |
{ | |
[RequireComponent(typeof(Drone))] | |
public class DroneControllerInput : MonoBehaviour | |
{ | |
private Drone drone; | |
private void Start() { | |
drone = this.gameObject.GetComponent<Drone>(); | |
} | |
private void LateUpdate() | |
{ | |
if (drone.ControllerAllowed()) | |
{ | |
AirSimRCData rcData = drone.GetRCData(); | |
rcData.is_valid = true; | |
rcData.roll = Input.GetAxis("Horizontal"); | |
rcData.pitch = Input.GetAxis("Vertical"); | |
rcData.throttle = Input.GetAxis("Depth"); | |
rcData.yaw = Input.GetAxis("Yaw"); | |
rcData.left_z = 0; | |
rcData.right_z = 0; | |
rcData.switch1 = (uint)(Input.GetKeyDown("joystick button 0") ? 1 : 0); | |
rcData.switch2 = (uint)(Input.GetKeyDown("joystick button 1") ? 1 : 0); | |
rcData.switch3 = (uint)(Input.GetKeyDown("joystick button 2") ? 1 : 0); | |
rcData.switch4 = (uint)(Input.GetKeyDown("joystick button 3") ? 1 : 0); | |
rcData.switch5 = (uint)(Input.GetKeyDown("joystick button 4") ? 1 : 0); | |
rcData.switch6 = (uint)(Input.GetKeyDown("joystick button 5") ? 1 : 0); | |
rcData.switch7 = (uint)(Input.GetKeyDown("joystick button 6") ? 1 : 0); | |
rcData.switch8 = (uint)(Input.GetKeyDown("joystick button 7") ? 1 : 0); | |
drone.SetRCData(rcData); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment