private void Awake() { // Set up the reference to the aeroplane controller. m_Aeroplane = GetComponent <AeroplaneController>(); if (GameInputController.Instance().GetDevice() != null) { m_Aeroplane.isJoystick = true; } }
private void FixedUpdate() { // Read input for the pitch, yaw, roll and throttle of the aeroplane. float roll = 0; float pitch = 0; bool airBrakes = false; float throttle = -1; float yaw = 0; // roll= CrossPlatformInputManager.GetAxis("Horizontal"); // pitch= CrossPlatformInputManager.GetAxis("Vertical"); // airBrakes = CrossPlatformInputManager.GetButton("Fire1"); // roll=Input.GetAxis("joystick 1 analog 0"); if (GameInputController.Instance().GetDevice() != null) { roll = GameInputController.Instance().GetAxis("Analog0"); pitch = -GameInputController.Instance().GetAxis("Analog1"); yaw = GameInputController.Instance().GetAxis("Analog2"); } else { if (Input.GetKey(KeyCode.UpArrow)) { pitch = 1; } if (Input.GetKey(KeyCode.DownArrow)) { pitch = -1; } if (Input.GetKey(KeyCode.LeftArrow)) { roll = -1; } if (Input.GetKey(KeyCode.RightArrow)) { roll = 1; } if (Input.GetKey(KeyCode.Q)) { pow += Time.fixedDeltaTime; } if (Input.GetKey(KeyCode.W)) { pow -= Time.fixedDeltaTime; } pow = Mathf.Clamp(pow, -1, 1); // roll=CrossPlatformInputManager.GetAxis("Horizontal"); // pitch= CrossPlatformInputManager.GetAxis("Vertical"); PlayerController.Instance().powBar.fillAmount = (pow + 1) * 0.5f; } // auto throttle up, or down if braking. // Debug.Log(GameInputController.Instance().GetDevice()); if (GameInputController.Instance().GetDevice() != null) { airBrakes = false; throttle = -GameInputController.Instance().GetAxis("Analog3"); PlayerController.Instance().powBar.fillAmount = (throttle + 1) * 0.5f; } else { airBrakes = Input.GetKey(KeyCode.LeftShift); throttle = airBrakes ? -1 : pow; } // Debug.Log(throttle); #if MOBILE_INPUT AdjustInputForMobileControls(ref roll, ref pitch, ref throttle); #endif // Pass the input to the aeroplane if (GameInputController.Instance().GetDevice() != null) { m_Aeroplane.Move(roll, pitch, yaw, (throttle + 1) * 0.5f, airBrakes); } else { m_Aeroplane.Move(roll, pitch, yaw, throttle, airBrakes); } }
void Update() { if (GameInputController.Instance().GetButton(mainWeaponButton) || Input.GetKey(KeyCode.Z)) { player.GetMainWeapon().FireButton(); } if (GameInputController.Instance().GetButtonDown(mainWeaponButton) || Input.GetKeyDown(KeyCode.Z)) { player.GetMainWeapon().FireButtonDown(); } if (GameInputController.Instance().GetButtonUp(mainWeaponButton) || Input.GetKeyUp(KeyCode.Z)) { player.GetMainWeapon().FireButtonUp(); } if (GameInputController.Instance().GetButton(secondaryWeaponButton) || Input.GetKey(KeyCode.X)) { player.GetSecondaryWeapon().FireButton(); } if (GameInputController.Instance().GetButtonDown(secondaryWeaponButton) || Input.GetKeyDown(KeyCode.X)) { player.GetSecondaryWeapon().FireButtonDown(); } if (GameInputController.Instance().GetButtonUp(secondaryWeaponButton) || Input.GetKeyUp(KeyCode.X)) { player.GetSecondaryWeapon().FireButtonUp(); } if (GameInputController.Instance().GetButton(specialWeaponButton) || Input.GetKey(KeyCode.C)) { player.GetSpecialWeapon().FireButton(); } if (GameInputController.Instance().GetButtonDown(specialWeaponButton) || Input.GetKeyDown(KeyCode.C)) { player.GetSpecialWeapon().FireButtonDown(); } if (GameInputController.Instance().GetButtonUp(specialWeaponButton) || Input.GetKeyUp(KeyCode.C)) { player.GetSpecialWeapon().FireButtonUp(); } if ((GameInputController.Instance().GetButtonDown(mainSwitchButton) && !GameInputController.Instance().GetButton(mainWeaponButton)) || (Input.GetKeyDown(KeyCode.A) && !Input.GetKey(KeyCode.Z))) { player.SwitchMainWeapon(); //Debug.Log(player.GetMainWeapon().name); } if ((GameInputController.Instance().GetButtonDown(secondarySwitchButton) && !GameInputController.Instance().GetButton(secondaryWeaponButton)) || (Input.GetKeyDown(KeyCode.S) && !Input.GetKey(KeyCode.X))) { player.SwitchSecondaryWeapon(); //Debug.Log(player.GetSecondaryWeapon().name); } if ((GameInputController.Instance().GetButtonDown(specialSwitchButton) && !GameInputController.Instance().GetButton(specialWeaponButton)) || (Input.GetKeyDown(KeyCode.D) && !Input.GetKey(KeyCode.C))) { if (!player.GetSpecialWeapon().inSpecialState) { player.SwitchSpecialWeapon(); } //Debug.Log(player.GetSpecialWeapon().name); } //txtWeapon.text=string.Format("W1: {0}\nW2: {1}\nSP: {2}",player.GetMainWeapon().weaponName,player.GetSecondaryWeapon().weaponName,player.GetSpecialWeapon().weaponName ); mainWeaponText.text = player.GetMainWeapon().weaponName; mainWeaponIcon.texture = player.GetMainWeapon().weaponIcon; secondaryWeaponText.text = player.GetSecondaryWeapon().weaponName; secondaryWeaponIcon.texture = player.GetSecondaryWeapon().weaponIcon; specialWeaponText.text = player.GetSpecialWeapon().weaponName; specialWeaponIcon.texture = player.GetSpecialWeapon().weaponIcon; Detect(); }