// Update is called once per frame void Update() { switch (stage) { case Stage.None: break; case Stage.WaitingForGuided: if (droneAction.IsGuided()) { Debug.Log("arm"); droneAction.Arm(); stage = Stage.WaitingForArmed; } break; case Stage.WaitingForArmed: if (droneAction.IsArmed()) { Debug.Log("takeoff"); droneAction.TakeOff(); stage = Stage.WaitingForTakeoffDone; } break; case Stage.WaitingForTakeoffDone: if (transform.position.y > 0.9f) { Debug.Log("switch to poshold"); droneAction.Poshold(); stage = Stage.WaitingForPosHold; } break; default: break; } }
private void Update() { if (Gamepad.current != null) { controlCd -= Time.deltaTime; if (controlCd <= 0) { controlCd = 0.1f; /*if (droneAction.IsPosHold()) * { * float alt = drone.transform.position.y; * if (alt > 1.2f && throttle > 500) * { * throttle = 500; * } * else if (alt < 0.7f && throttle < 500) * { * throttle = 500; * } * }*/ droneAction.ManualControl(pitch, roll, throttle, yaw); } } checkCd -= Time.deltaTime; if (checkCd <= 0) { checkCd = 1f; switch (stage) { case Stage.WaitingForGuided: if (droneAction.IsGuided()) { Debug.Log("arm"); droneAction.Arm(); stage = Stage.WaitingForArmed; } break; case Stage.WaitingForArmed: if (droneAction.IsArmed()) { Debug.Log("takeoff"); droneAction.TakeOff(); stage = Stage.WaitingForTakeoffDone; } break; case Stage.WaitingForTakeoffDone: if (drone.transform.position.y > 0.9f) { Debug.Log("switch to poshold"); droneAction.Poshold(); stage = Stage.WaitingForPosHold; } break; case Stage.WaitingForPosHold: if (droneAction.IsPosHold()) { stage = Stage.None; } else { droneAction.Poshold(); } break; } } }