// crouching only if able to crouch and not in the air. // you can crouch the instant you land and hold the crouch button like in OW. private void HandleCharacterCrouch() { if (isAbleToCrouch && isGrounded) { if (m_InputHandler.GetCrouchInput() && !isCrouching) { SetCrouchingState(!isCrouching, false); } else if (isCrouching && (m_InputHandler.GetCrouchInputReleased() || !m_InputHandler.GetCrouchInput())) { SetCrouchingState(false, false); } } }
void Update() { if (timerActive) { timer += Time.deltaTime; int timeInSecondsInt = (int)timer; //We don't care about fractions of a second, so easy to drop them by just converting to an int int minutes = timeInSecondsInt / 60; //Get total minutes int seconds = timeInSecondsInt - (minutes * 60); //Get seconds for display alongside minutes timerText.text = minutes.ToString("D2") + ":" + seconds.ToString("D2"); } hasJumpedThisFrame = false; bool wasGrounded = isGrounded; GroundCheck(); // landing if (isGrounded && !wasGrounded) { //Can add fall damage //play landing sound lensdis.intensity.value = 0; vignett.intensity.value = 0; chrome.intensity.value = 0; } // crouching if (m_InputHandler.GetCrouchInputDown()) { addforce(transform.forward, slideSpeed); //lensdis.intensity.value = -60; chrome.intensity.value = 1; //vignett.intensity.value = 0.5f; SetCrouchingState(true, false); } if (m_InputHandler.GetCrouchInputReleased()) { lensdis.intensity.value = 0; chrome.intensity.value = 0; vignett.intensity.value = 0; SetCrouchingState(false, false); } UpdateCharacterHeight(false); HandleCharacterMovement(); if (isCrouching) { addforce(transform.forward, slideSpeed); } if (Input.GetAxis("Mouse ScrollWheel") > 0f) // forward { if (activeWeapon >= 1 && weaponList.Count > 1) { weaponList[activeWeapon].SetActive(false); activeWeapon -= 1; weaponList[activeWeapon].SetActive(true); } } else if (Input.GetAxis("Mouse ScrollWheel") < 0f) // backwards { if (activeWeapon < (weaponList.Count - 1) && weaponList.Count > 1) { weaponList[activeWeapon].SetActive(false); activeWeapon += 1; weaponList[activeWeapon].SetActive(true); } } if (transform.position.y < -30) { transform.position = checkpoints[checkpoints.Count - 1]; } }