// ============================================================== // MonoBehaviour Methods // ============================================================== void Start() { PlayerTransform = GetComponent <Transform>(); _rb2dPlayer = GetComponent <Rigidbody2D>(); // assign the speed values from configuration data //_vertSpeed = ConfigUtils.VertSpeed; //_horiSpeed = ConfigUtils.HoriSpeed; //_horiSpeedBuffed = ConfigUtils.HoriSpeedBuffed; // Android platform has trouble reading config streaming assets, thus directly assign _vertSpeed = 10.0f; _horiSpeed = 0.2f; _horiSpeedBuffed = 0.6f; // initialise the vertical movement state with still where the player keeps the altitude VertMvtState = new VertMvtState(); VertMvtState = VertMvtState.Still; // initialise the horizontal movement state with normal where the player keeps steady speed HoriMvtState = new HoriMvtState(); HoriMvtState = HoriMvtState.Normal; // assign the player movement upper lower limits _playerMvtUpperLimit = ScreenUtils.ScreenTop - 1.5f; _playerMvtLowerLimit = ScreenUtils.ScreenBottom + 2.0f; }
// ----- Keyboard Control ----- private void KeyboardControl() { if (Input.GetKey(KeyCode.S)) { VertMvtState = VertMvtState.MovingDown; } else if (Input.GetKey(KeyCode.W)) { VertMvtState = VertMvtState.MovingUp; } else { VertMvtState = VertMvtState.Still; } }
// ----- Phone Sensor Control ----- private void PhoneSensorControl() { if (Input.acceleration.y < -0.60) { VertMvtState = VertMvtState.MovingDown; } else if (Input.acceleration.y > -0.25) { VertMvtState = VertMvtState.MovingUp; } else { VertMvtState = VertMvtState.Still; } }