// Update is called once per frame void Update() { var padState = GamePad.GetState(); if (GamePad.AnyConnected()) // if using gamepad { // start button is pressed if (padState.Pressed(CButton.Start)) { ToggleMenu(); } // Right bumper is held, and right stick is pressed if (GamePad.GetButton(CButton.RB, carbonInputId) && padState.Pressed(CButton.LS)) { // reload current level SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); } // right bumper is held and left bumper is pressed if (GamePad.GetButton(CButton.RB, carbonInputId) && padState.Pressed(CButton.LB)) { // go to first level SceneManager.LoadScene(0); } } else // if using keyboard { // start button is pressed if (Input.GetKeyDown(KeyCode.M)) { ToggleMenu(); } // Shift is held and R is pressed if (Input.GetKey(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.R)) { // reload current level SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); } // R is held and G is pressed if (Input.GetKey(KeyCode.R) && Input.GetKeyDown(KeyCode.G)) { // go to first level SceneManager.LoadScene(0); } } // calculate input movement direction Vector2 move = new Vector2( GamePad.GetAxis(CAxis.LX, carbonInputId), 0); UpdateJumping(); UpdateMovement(move); }
private void OnGUI() { var padState = GamePad.GetState(); if (GamePad.AnyConnected()) { if (GUI.Button(new Rect(5, 5, 150, 30), "Menu (press Start)")) { ToggleMenu(); } } else { if (GUI.Button(new Rect(5, 5, 150, 30), "Menu (M)")) { ToggleMenu(); } } if (toggleMenu) { var verticalPadding = 40; var verticalStartPos = 50; var horizontalStartPos = 60; var horizontalPadding = 250; if (GamePad.AnyConnected()) { GUI.Label(new Rect(horizontalStartPos, verticalStartPos, horizontalPadding, verticalPadding), "Left Stick.....Move"); verticalStartPos += verticalPadding; GUI.Label(new Rect(horizontalStartPos, verticalStartPos, horizontalPadding, verticalPadding), "A.....Jump"); verticalStartPos += verticalPadding; GUI.Label(new Rect(horizontalStartPos, verticalStartPos, horizontalPadding, verticalPadding), "Hold right bumper + Press left bumper......Restart Level"); verticalStartPos += verticalPadding; GUI.Label(new Rect(horizontalStartPos, verticalStartPos, horizontalPadding, verticalPadding), "Hold right bumper + Press left stick......Restart Game"); verticalStartPos += verticalPadding; } else { GUI.Label(new Rect(horizontalStartPos, verticalStartPos, horizontalPadding, verticalPadding), "WASD.....Move"); verticalStartPos += verticalPadding; GUI.Label(new Rect(horizontalStartPos, verticalStartPos, horizontalPadding, verticalPadding), "Space.....Jump"); verticalStartPos += verticalPadding; GUI.Label(new Rect(horizontalStartPos, verticalStartPos, horizontalPadding, verticalPadding), "Shift + R......Restart Level"); verticalStartPos += verticalPadding; GUI.Label(new Rect(horizontalStartPos, verticalStartPos, horizontalPadding, verticalPadding), "R + G......Restart Game"); verticalStartPos += verticalPadding; } } }