// Update is called once per frame void Update() { if (gameComplete) { gameCompleteTimer += Time.deltaTime; if (gameCompleteTimer >= 3f && (MobileInput.GetTouchDown() || Input.GetButtonDown("Boost"))) { SceneManager.LoadScene("Menu"); } } }
// Update is called once per frame void Update() { ReduceTimerIfDamaged(); // Update Effects while boosting if (mobileInputMode ? MobileInput.GetTouchDown() : Input.GetButtonDown("Boost")) { trailEffectsManager.StartCharging(); } // Slow down and charge if (mobileInputMode ? MobileInput.GetTouched() : Input.GetButton("Boost")) { bool previouslyCharged = speedCharge >= maxChargeTime; speedCharge += Time.deltaTime; RainFromCharge(rainFromChargeDistance, playerRainRadius); if (!previouslyCharged && speedCharge >= maxChargeTime) { trailEffectsManager.BoostReady(); } } // return to glide if (sphericalMovementVector.magnitude > minGlideSpeed) { sphericalMovementVector = sphericalMovementVector.normalized * Mathf.Max(minGlideSpeed, sphericalMovementVector.magnitude - Time.deltaTime * returnToGlideRate); } // Get input Vector3 movementDirectionScreenSpace = Camera.main.transform.InverseTransformDirection(Vector3.Cross(sphericalMovementVector, transform.position)).normalized; Vector3 inputDirection = Vector3.zero; if (mobileInputMode) { if (Input.touchCount > 0) { // flatten screen space position Vector3 positionScreenSpace = Camera.main.WorldToScreenPoint(transform.position); movementDirectionScreenSpace.z = 0; // Convert touch to 3d vector Vector3 touchPositionScreenSpace = new Vector3(Input.touches [0].position.x, Input.touches [0].position.y, 0); inputDirection = (positionScreenSpace - touchPositionScreenSpace) / minTouchDistanceFromPlayerToTurnScreenSpace; inputDirection *= -1; previousInputMovementDirection = inputDirection; } else { inputDirection = previousInputMovementDirection; } } else if (mouseInputMode) { if (Input.GetButton("Boost")) { Vector3 positionScreenSpace = Camera.main.WorldToScreenPoint(transform.position); movementDirectionScreenSpace.z = 0; inputDirection = (positionScreenSpace - Input.mousePosition) / minMouseDistanceFromPlayerToTurnScreenSpace; inputDirection *= -1; previousInputMovementDirection = inputDirection; } else { inputDirection = previousInputMovementDirection; } } else { inputDirection = (new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0)); inputDirection *= 1.5f; if (inputDirection.magnitude > 1.0f) { inputDirection = inputDirection.normalized; } } // Steer and brake inputDirection.z = 0; Steer(inputDirection, movementDirectionScreenSpace, mobileInputMode ? MobileInput.GetTouched() : Input.GetButton("Boost")); // Push to above min speed if (sphericalMovementVector.magnitude < minSpeed) { sphericalMovementVector = minSpeed * sphericalMovementVector.normalized; } // Move transform.RotateAround(Vector3.zero, sphericalMovementVector, sphericalMovementVector.magnitude * Time.deltaTime); // Boost if (mobileInputMode ? MobileInput.GetTouchUp() : Input.GetButtonUp("Boost")) { // If we've been charging long enough if (speedCharge >= maxChargeTime) { Quaternion boostDirectionTurn = Quaternion.AngleAxis(boostTurnAmount, transform.position); sphericalMovementVector = (Mathf.Min(1f, speedCharge / maxChargeTime) * (maxBoostSpeed - minBoostSpeed) + minBoostSpeed) * (boostDirectionTurn * sphericalMovementVector.normalized); if (sphericalMovementVector.magnitude > maxSpeed) { sphericalMovementVector = sphericalMovementVector.normalized * maxSpeed; } // Shake camera Vector3 shakeDirection = Camera.main.transform.InverseTransformDirection(Vector3.Cross(sphericalMovementVector, transform.position)); shakeDirection.z = 0; shakeDirection.Normalize(); Camera.main.GetComponent <CameraShaker>().ShakeInDirectionWithIntensity(shakeDirection, boostCameraShakeIntensity, CameraShaker.ShakeType.Smooth); trailEffectsManager.Boost(); RainFromBoost(rainFromBoostDistance, playerRainRadius, rainFromBoostSpreadDegrees); } boostTurnAmount = 0; speedCharge = 0f; trailEffectsManager.StopCharging(); } // Look Vector3 lookDirection = Quaternion.AngleAxis(boostTurnAmount, transform.position) * sphericalMovementVector; directionIndicator.transform.rotation = Quaternion.LookRotation(lookDirection, transform.position.normalized); // Update Visual Components trailEffectsManager.UpdateMovement(sphericalMovementVector, lookDirection, maxChargeDirectionAngle); trailEffectsManager.UpdateSpeed((sphericalMovementVector.magnitude - minSpeed) / (maxSpeed - minSpeed)); }