private void Awake() { controls = new FPSPlayerControls(); controls.UI.Pause.performed += ctx => { ToggleMenu(); }; saveGameButton.onClick.AddListener(() => { // todo: get rid of this, and make sure the game is saved when it needs to be. // having a button like this makes players feel unsure about whether or not // they need to use it, and when. GameManager.Instance.SaveGame(); }); exitArenaButton.onClick.AddListener(() => { ToggleMenu(); SceneWrangler.Instance.LoadScene("Scenes/HoldingCell"); }); exitTitleButton.onClick.AddListener(() => { ToggleMenu(); UnlockCursor(); SceneWrangler.Instance.LoadScene("Scenes/MainMenu"); }); immortalMode.onValueChanged.AddListener((isOn) => { // set this value on the player controller OnImmortalToggle?.Invoke(isOn); PlayerPrefs.SetInt(IMMORTAL_MODE_KEY, isOn ? 1 : 0); PlayerPrefs.Save(); }); volumeSlider.onValueChanged.AddListener(level => { var volumeAdjust = level == 0 ? -80f : 10 * Mathf.Log10(level); var adjustedVolume = Mathf.Clamp(baseVolume + volumeAdjust, -80f, 0f); // ensure bad math isn't exploding eardrums. audioMixer.SetFloat("master_volume", adjustedVolume); PlayerPrefs.SetFloat(MainMenuHandler.VOLUME_PREF_KEY, level); PlayerPrefs.Save(); }); }
private void Awake() { controls = new FPSPlayerControls(); // Fire controls playerActions = controls.Player; playerActions.Fire.performed += ctx => { isFiring = true; }; playerActions.Fire.canceled += ctx => { isFiring = false; }; // Movement controls playerActions.Move.performed += ctx => { isMoving = true; }; playerActions.Move.canceled += ctx => { isMoving = false; }; playerActions.Jump.performed += ctx => { isJumping = true; }; playerActions.Jump.canceled += ctx => { isJumping = false; }; playerActions.Dash.performed += ctx => { if (canDash) { StartCoroutine(Dash()); } }; playerActions.Interact.performed += ctx => { if (interactionTarget) { interactionTarget.started += () => { Cursor.lockState = CursorLockMode.None; Cursor.visible = true; playerActions.Disable(); }; interactionTarget.finished += () => { Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; playerActions.Enable(); }; interactionTarget.HandleInteraction(gameObject); } }; // Swap Weapon Controls playerActions.ScrollWeapon.performed += ctx => { if (!isSwitchingWeapon) { var input = ctx.ReadValue <Vector2>(); var scrollDirectionRaw = Mathf.RoundToInt(input.y == 0 ? input.x : input.y); StartCoroutine(SwitchingWeaponDelay(weaponSwitchDuration)); OnWeaponScroll?.Invoke(Mathf.RoundToInt(scrollDirectionRaw)); activeWeapon = weaponSwitcher.GetActiveWeapon()?.GetComponent <FPSWeapon>(); } }; }