// Update is called once per frame void Update() { if (!canControl) { return; } // Handle input communication with the motor. Since this is a side scrolling platformer, we do not want // any vertical movement. So only set the x. Vector2 moveDir = new Vector2(); moveDir.x = Input.GetAxis(PC2D.Input.HORIZONTAL); motor.movementDir = moveDir; // Jump? if (Input.GetButtonDown(PC2D.Input.JUMP)) { motor.Jump(); } if (Input.GetButton(PC2D.Input.JUMP)) { // Held down? motor.JumpHeld(); } if (Input.GetButtonDown(PC2D.Input.DASH)) { motor.Dash(); } }
// Update is called once per frame void Update() { if (!canControl) { return; } if (Input.GetButtonDown(PC2D.Input.DASH)) { motor.Dash(lastHeading); } else { Vector2 moveDir = new Vector2(); moveDir.x = Input.GetAxisRaw(PC2D.Input.HORIZONTAL); moveDir.y = Input.GetAxisRaw(PC2D.Input.VERTICAL); if (Mathf.Abs(moveDir.x) < PC2D.Globals.INPUT_THRESHOLD) { moveDir.x = 0; } if (Mathf.Abs(moveDir.y) < PC2D.Globals.INPUT_THRESHOLD) { moveDir.y = 0; } // If not zero then normalize. if (moveDir != Vector2.zero) { moveDir.Normalize(); lastHeading = moveDir; } motor.movementDir = moveDir; } }